[英]Re-writing Dynamic URL with .htaccess
I'd like to remove the ".php" at the end of all webpages AND rewrite my dynamic urls for the section "example.com/archive?url=..." 我想删除所有网页末尾的“ .php”,并重写“ example.com/archive?url = ...”部分的动态网址。
What I got so far: 我到目前为止所得到的:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
This part works fine but now I also want to rewrite my dynamic urls for the following section of the website. 这部分工作正常,但现在我也想为网站的以下部分重写我的动态URL。
Old url: example.com/archive?url=test-article 旧网址: example.com/archive? url = test-article
New url: example.com/archive/test-article 新网址: example.com/archive/test-article
RewriteRule ^archive/([^/]+)$ archive?url=$1
This part doesn't work. 这部分不起作用。 What am I missing here?
我在这里想念什么?
It's used for an addon domain so maybe this has something to do with the problem? 它用于附加域,所以也许与问题有关?
EDIT 1: 编辑1:
I put some garbage in my .htaccess file and it generates an error so I know for sure it's reading the file. 我在.htaccess文件中放入了一些垃圾,它生成了一个错误,因此我确定它正在读取文件。
EDIT 2: 编辑2:
I disabled multiviews as proposed below but getting an internal server error now. 我按照以下建议禁用了多视图,但是现在出现内部服务器错误。 This is the error log:
这是错误日志:
[Tue May 20 13:12:12 2014] [error] [client (ip)] Request exceeded the limit of 10 internal redirects due to probable configuration error. [2014年5月20日星期二13:12:12] [错误] [客户端(ip)]由于可能的配置错误,请求超出了10个内部重定向的限制。 Use 'LimitInternalRecursion' to increase the limit if necessary.
必要时使用'LimitInternalRecursion'增加限制。 Use 'LogLevel debug' to get a backtrace
使用“ LogLevel调试”获取回溯
Edit 3: I found the solution 编辑3:我找到了解决方案
I solved the problem by changing the last rule into: 我通过将最后一条规则更改为解决了该问题:
RewriteRule ^news/([^/]+)$ archive?url=$1
Most likely you have options MultiViews
enabled. 您最有可能启用了
MultiViews
选项。
You can disable that using: 您可以使用以下方式禁用该功能:
Options -MultiViews
With MultiViews
disabled it will not not serve /file.php
when you request /file
. 禁用
MultiViews
,当您请求/file
时,它将不提供/file.php
服务。
EDIT: As per your revised question you can do: 编辑:根据您修改后的问题,您可以执行以下操作:
RewriteRule ^news/([^/]+)$ archive?url=$1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.