簡體   English   中英

htaccess遇到問題,請刪除.php和id =並添加斜杠

[英]Having some problems with htaccess remove .php and id= and add slash

我有這個htaccess,它幾乎可以正常工作,但是..

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.loggs\.no [NC]
RewriteRule ^(.*)$ https://loggs.no/$1 [L,R=301]

RewriteCond %{THE_REQUEST} \s/+show(?:\.php)?\?id=([0-9]+) [NC]
RewriteRule ^ show/%1? [R,L]

RewriteRule ^show/([0-9]+)/?$ show.php?id=$1 [L,QSA]

## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]

# add a trailing slash    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]

但這並沒有在我的所有頁面上添加斜杠,當我單擊show/6 ,它將轉到例如 Show/3 ,直到show/show/3為止,我想為我的所有內容刪除.php頁面。

您可以在網站根目錄.htaccess中使用以下規則:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.(loggs\.no)$ [NC]
RewriteRule ^(.*?)/?$ https://%1/$1/ [L,R=301,NE]

RewriteCond %{THE_REQUEST} \s/+(show|feeds|links)(?:\.php)?\?id=([0-9]+) [NC]
RewriteRule ^ %1/%2/? [R=301,NE,L]

## hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} \s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R=301,NE,L]

# add a trailing slash    
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]

RewriteRule ^(show|feeds|links)/([0-9]+)/?$ $1.php?id=$1 [L,QSA,NC]

RewriteRule ^(show|feeds|links)/?$ $1.php [L,NC]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM