我有一个这样的网址 https://rockmobile.pk/detail/oneplus6 并希望删除单词“ detail”并仅显示产品名称,例如 https://rockmobile.pk/oneplus6.html。我在公用文件夹中的.htaccess文件是
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule ^([^-]*).html$ detail/$1/ [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
重写规则
RewriteRule ^([^-]*).html$ detail/$1/ [L]
要检测/oneplus6.html,但网址已更改为/ detail / oneplus6
(在localhost apache wampserver上测试过)
http://localhost/projectName/public/oneplus6.html 改成 http://localhost/projectName/public/detail/oneplus6
答案 0 :(得分:1)
您需要使用重写规则中的[P]
,以便它将代理请求
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteRule ^([^-]*).html$ detail/$1/ [P]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>