网址:http://domainname.com/index.php?p=top-games
我需要将其重写为http://domainname.com/top-games
我是如何使用htaccess文件执行此操作的?请任何人都可以给我htaccess代码。
由于
答案 0 :(得分:0)
试试这个:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]
</IfModule
在根文件夹中创建.htaccess文件并粘贴代码
答案 1 :(得分:0)
您可能正在寻找反向重定向。
将此代码放入DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/?$ /index.php?q=$1 [L,QSA]