我试图重写某个php文件的网址。
瞄准网址:www.mysite.com/filename/topic/
或www.mysite.com/filename/topic
什么有用:www.mysite.com/filename
和www.mysite.com/topic
我已经尝试了所有重写规则,我知道哪些应该有效,但每次我将主题添加到网址时,我最终会得到500 internal server error
当前.htacces文件
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
//No need for php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
//Rewriting the url
RewriteRule ^([a-zA-Z0-9_-]+)$ filename.php?topic=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ filename.php?topic=$1
答案 0 :(得分:0)
您的规则存在冲突,与MultiViews的内容协商可能存在问题。此外,您没有使用所有标志([L])需要阻止规则匹配的继续。
你不能用第二套规则这样做,你不需要2个规则只是为了/
。你可以选择它。你需要做这样的事情。
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?topic=$2 [L]
</IfModule>