简体   繁体   English

htaccess将所有页面重写为相同的规则

[英]htaccess rewrite all pages to same rule

I have added a rewrite rule in htaccess file and it is working fine the only problem is if I open any URL from after 2016 directory it opens the same target file. 我在htaccess文件中添加了重写规则,并且工作正常,唯一的问题是,如果我从2016目录之后打开任何URL,它将打开相同的目标文件。

RewriteRule ^elections/assembly/2016/(.*)$ elections/assembly/2016/index.php?state=$1

For example :- 例如 :-

http://www.example.com/elections/assembly/2016/dir1/dir2/index.php http://www.example.com/elections/assembly/2016/dir1/dir2/index.php

the above URL follow the same pattern. 上面的URL遵循相同的模式。 please help me to resolve this. 请帮我解决这个问题。

You have to exclude your real files and dirs from the rule : 您必须从规则中排除您的真实文件和目录:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^elections/assembly/2016/(.*)$ elections/assembly/2016/index.php?state=$1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM