我有这个网址:https://example.com/sub/product而且我不想显示" sub"在我的网址中,以便最终的网址看起来像https://example.com/product,并将索引的网址重定向到此网址。可能吗?这是我目前的.htaccess文件:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ReWriteRule ^([a-z\-0-9]+)$ index.php?goto=$1 [L,NC]
ReWriteRule ^([a-z\-]+)/([a-z\-0-9]+)$ index.php?goto=$1&catidx=$2 [L,NC]
ErrorDocument 404 /404/404.php
答案 0 :(得分:0)
您可以使用以下内容:
RewriteEngine on
#--redirect from "/sub/foo to "/foo"--#
RewriteCond %{THE_REQUEST} /sub/([^\s]+) [NC]
RewriteRule ^ /%1 [L,R]
#--rewrite "/foo" to its orignal location "/sub/foo"
RewriteRule %{REQUEST_FILENAME} !-d
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /sub/$1 [L,QSA]