Php .htaccess获取重写问题
我已经在这个问题上纠缠了好几天了,并尝试了使用.htaccess文件的多种配置,但我已经穷途末路了。这就是我目前所拥有的Php .htaccess获取重写问题,php,apache,.htaccess,mod-rewrite,url-rewriting,Php,Apache,.htaccess,Mod Rewrite,Url Rewriting,我已经在这个问题上纠缠了好几天了,并尝试了使用.htaccess文件的多种配置,但我已经穷途末路了。这就是我目前所拥有的 Options +FollowSymLinks -MultiViews RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !\..+$ RewriteCond %{REQUEST_URI} !/$ RewriteRule ^(.*)$ ht
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L]
RewriteRule ^(.*)/$ $1.php [L]
RewriteRule ^product/([a-z]+)$ /product.php?product_id=$1 [QSA,L]
它正确地重写了PHP扩展的url,并在我的url中添加了一个尾随斜杠。我的问题是最后一行。我希望所有对产品(如mywebsite.com/product/1234)的url请求都传递到我的脚本(如mywebsite.com/product.php?product_id=1234)
当我转到mywebsite.com/product/1234/时,我得到一个“404未找到”,错误为“在该服务器上找不到请求的URL/base_dir/1234.php”
我与Go Daddy共享主机。原因是当您转到:
http://mywebsite.com/product/1234/
,您的第二个最后一个重写规则
(请注意,[L]
指定此重定向后不再进行重写):
应该将您重定向到:http://mywebsite.com/product/1234.php
我不太熟悉.htaccess规则,但您应该交换最后一行和最后第二行的位置:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^product/([a-z]+)$ /product.php?product_id=$1 [QSA,L]
RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L]
RewriteRule ^(.*)/$ $1.php [L]
感谢您回复Stoic,但不幸的是,当我尝试时收到错误“此页面有重定向循环”。
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^product/([a-z]+)$ /product.php?product_id=$1 [QSA,L]
RewriteRule ^(.*)$ http://mywebsite.com/$1/ [L]
RewriteRule ^(.*)/$ $1.php [L]