URL RewriteEngine内部服务器错误

时间:2014-03-23 20:26:32

标签: .htaccess

我在.htaccess中使用以下配置尝试将http://www.mysite.com/subdir/page.php?param=4格式的网址重写为http://www.mysite.com/subdir/page/param/4

# Turn on the rewrite engine
Options +FollowSymlinks
RewriteEngine on

# Request routing
RewriteRule ^([a-zA-Z_-]*)$   index.php?name=$1 [nc,qsa]

但是,当我访问该页面时,我收到内部服务器错误。配置有问题吗?

编辑:我已将其更新为以下内容,但现在它似乎没有进行任何重写,当我尝试使用http://www.mysite.com/subdir/param/2这样的网址时,会给我404;

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^name=([0-9]+)$ [NC]
RewriteRule ^project-testing/ws/index.php$ /project-testing/ws/name/%1 [R=301,NC,L]

1 个答案:

答案 0 :(得分:0)

您需要使用%{QUERY_STRING}来读取您的网址的查询字符串,以便根据它进行重定向。

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^param=([0-9]+)$ [NC]
RewriteRule ^subdir/page.php$ subdir/page/param/%1 [R=301,NC,L]

或者如果您想要访问:

http://www.mysite.com/subdir/page/param/4

显示以下内容:

http://www.mysite.com/subdir/page.php?param=4

那就是这样的:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^subdir/page/([^/]+)/([^/]+)$ subdir/page.php?$1=$2 [NC,L]
相关问题