2012-01-17 2 views
0

가끔 발생합니다. 내 htaccess 파일에서 엉망이라고 말하는 것을 만들었습니다. 몇 가지 문제가 있습니다. 내부적으로 반복적으로 반복되는 것을 알고 있으며, 어쨌든이 문제는 훌륭하지 않습니다. 수십개의 질문에 대해 수십 번 살펴 보았고 수많은 해결책을 시도했습니다. 최종 결과는 여러 부분으로 구성된 문제에 대해 하나 이상의 솔루션을 하나로 모으기 위해 노력하고 있으며 난 정말 혼란스러워했습니다. 이것은 독점적으로 며칠 동안의 나의 사명이었습니다. 나는 붙어있다. 나쁜.Mod_rewrite에 슬래시를 추가하고 가상 디렉토리에서 슬래시가 아닌 슬래시를 리디렉션

  • 나는 mydomain.com/handmade-jewelry는 사용자 도메인/수제 - 보석/(주 슬래시)로 가고 싶어
  • 그리고 나는 또한이 .COM/수제 - 보석/쥬얼리 - 세부 사항에가는 일부 조각 .php? id = some-piece. 그것도 효과가 있지만 슬래시가 필요합니다.
  • "/ some-piece /"에 후행 슬래시를 표시하려고하면 찾을 수없는 파일이 리디렉션되고 조회됩니다.

나를 신뢰하십시오. 나는 내 논리의 결함이 눈에 띄도록해야한다는 것을 알고 있으며 토요일 이후이 질문을하지 않았다. 나는 이것이 super-oft 물었다라는 것을 알고있다. 나는 내가 죽은 채로 붙어 있지 않은지 묻지 않을 것이다.

(rewrite all www and non-www requests to https:// ...works fine) 
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] 
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L] 
RewriteCond %{HTTPS} !=on 
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 
RewriteCond %{SERVER_PORT} ^80$ 
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

(redirecting to the page with all the jewelry) 
RewriteRule ^handmade-jewelry/$ jewelry-inventory-page.php [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
(following was a failed attempt.) 
# RewriteCond %{REQUEST_URI} !rock-jewelry/(.*)/$ 
(following works with no trailing slash, which is needed) 
RewriteRule ^handmade-jewelry/(.*)$ jewelry-details.php?s=$1 [L] 
(if I turn this on, it goes to a 404 looking for "handmade-jewelry/this-piece/index.php?s=thispiece/etc...") 
# RewriteRule ^handmade-jewelry/(.*)?/$ jewelry-details.php?s=$1 [L] 

죄송합니다. 나는 너에게 많은 것을 안다. 이런 종류의 질문은 불필요해진다.

답변

2

보십시오 사이트

RewriteEngine on 
RewriteBase/

#(rewrite all www and non-www requests to https:// ...works fine) 
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] 
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L] 
RewriteCond %{HTTPS} !=on 
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

#I believe this is redundant because of the previous rule 
RewriteCond %{SERVER_PORT} ^80$ 
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] 

#if existing file or directory 
RewriteCond %{REQUEST_FILENAME} -f [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
#do nothing 
RewriteRule^- [L] 


#if it does not end with a slash e.g. handmade-jewelry, redirect to with slash 
RewriteRule ^([-a-zA-Z0-9]+)$ /$1/ [L,R=301] 

#if it does not end with a slash e.g. handmade-jewelry/some-piece, add the slash 
RewriteRule ^([-a-zA-Z0-9]+/[-a-zA-Z0-9]+)$ /$1/ [L,R=301] 

#(redirecting to the page with all the jewelry) 
RewriteRule ^handmade-jewelry/$ jewelry-inventory-page.php [L,NC] 

RewriteRule ^handmade-jewelry/([-a-zA-Z0-9]+)/$ jewelry-details.php?s=$1 [L,NC] 
+0

오의 루트 디렉토리에 당신의 htaccess로 파일에 다음을 추가! 나는 너에게 충분히 감사 할 수 없다! 그것은 절대적으로 완벽했으며 예상했던대로 정확하게 작동했습니다. 모든 것을 해줘서 고맙습니다. – Cyprus106

관련 문제