.htaccess URL重写引擎内部服务器错误
我正在使用.htaccess URL重写引擎内部服务器错误,.htaccess,.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=$
.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]
但是,当我访问该页面时,会出现一个内部服务器错误。配置有问题吗
编辑:我已将其更新为以下内容,但现在它似乎没有进行任何重写,当我尝试使用类似的URL时,它会给我一个404http://www.mysite.com/subdir/param/2
:
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]
您需要使用
%{QUERY\u STRING}
读取URL的查询字符串,以便根据该字符串重定向
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]
您请求的url是什么?我使用了以下代码(根据您在这里编写的内容修改为我的实际url):选项+FollowSymLinks-多视图
RewriteEngine on RewriteBase/RewriteCond%{QUERY_STRING}^name=([0-9]+)$[NC]RewriteRule^项目测试/ws/index.php$/project测试/ws/name/%1[R=301,NC,L]
但它不起作用。它只是说“找不到页面”,就好像没有进行重写一样。@rar@rar是一个数字,也可以是一个字符串。您试图访问哪个URL,结果是404?你在问题上提到的第一个?如果您想访问http://www.mysite.com/subdir/page/param/4
你必须使用我在回答中给你的第二个例子,仔细阅读:)name
可以是字符串(在这个例子中,唯一可用的数据意味着它将是字符串),重写的URL就是我试图访问的URL。所以http://www.mysite.com/subdir/page/param/4
@rar仅使用第二条规则,即我在答案上发布的规则。