2012-01-17 11 views
0

時々、私はhtaccessファイル内の熱い混乱と言うことを作りました。私はいくつかの問題を抱えています。私は機会に内部的にループしていることを知っています。私は数十のSOの質問を数十回見てきて、たくさんの解決策を試しました。最終的な結果は、私は複数の部分の問題に複数の別々の解決策をまとめようとしており、本当に混乱してしまったということです。これは排他的に私の使命でした。私は立ち往生している。悪い。私はその後、私も.COM /手作りジュエリー/いくつかのピースが、ジュエリー、細部に行く必要がありMYDOMAIN /手作りジュエリー/(ノートスラッシュ) Mod_rewriteにテーラリングスラッシュを追加し、バーチャルディレクトリ内のスラッシュをリダイレクトしない

  • に行きたいmydomain.com/handmade-jewelry

    • .php?id = some-piece。それは動作しますが、後続のスラッシュも必要です。
    • "/ some-piece /"に後ろにスラッシュを表示しようとすると、リダイレクトされ、見つからないファイルにヒットします。

    私を信頼してください。私はここに私の論理に傷をつけなければならないことを知っています、そして、私は土曜日以来この質問をすることに抵抗しました。私はこれが頼まれていることを知っています。私は死んでいないかどうか尋ねていないだろう。

    (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

    関連する問題