我有一个奇怪的情况,我的网站就像
www.example.com/page.php?url=homepage。我正在尝试使用.htaccess文件使网址看起来像
www.example.com/page/homepage/
通过在网址中隐藏“.php?url =”部分。这可能吗?请建议。
答案 0 :(得分:10)
试试这个:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# /anything/anything -> anything.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9_])/([^/]*)$ /$1.php?url=$2 [L]
</IfModule>
如果page.php
文件名始终相同,则按以下方式执行:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# /page/anything -> page.php?url=anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([^/]*)$ /page.php?url=$1 [L]
</IfModule>
答案 1 :(得分:4)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/(.*)/$ /page.php?url=$1 [L]
答案 2 :(得分:1)
RewriteRule ^([A-Za-z0-9 - ] +)/([A-Za-z0-9 - ] +)/?$ pagename.php?name = $ 1&amp; id = $ 2 [NC, L] 这段代码你可以隐藏你的页面名称