简体   繁体   English

.htaccess规则将所有网址重定向到同一位置

[英].htaccess rule redirects all urls to the same location

I am trying to modify one redirect rule but it is not working quite as I want it to. 我正在尝试修改一个重定向规则,但是它并没有按照我想要的那样工作。 Maybe someone can look into it and advice what needs to be corrected. 也许有人可以调查一下并提出需要纠正的建议。

I have this rule: 我有这个规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)/$ /page.php?id=$1 [L]

The rule redirects www.site.com/page.php?id=one to www.site.com/one/ which is what I need to do. 该规则将www.site.com/page.php?id=one重定向到www.site.com/one/ ,这是我需要做的。

However, the same rule redirects all other pages like www.site.com/about-us/ to www.site.com/page.php?id= . 但是,相同的规则会将所有其他页面(如www.site.com/about-us/重定向到www.site.com/page.php?id=

What needs to be changed in the rule to only redirect the page I want to and not all the others? 要仅重定向我想要的页面而不重定向所有其他页面,规则中需要更改什么?

You can restrict your rule: 您可以限制规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(one|two|three)/$ /page.php?id=$1 [L,QSA]

The only way I could think of is to insert insert an identifier key either in URL which you want to ignore or rewrite. 我能想到的唯一方法是在要忽略或重写的URL中插入一个标识符键。

eg below code will rewrite http://www.example.com/one-1/ by http://www.example.com/page.php?id=one-1 例如下面的代码将改写http://www.example.com/one-1/通过http://www.example.com/page.php?id=one-1

RewriteRule ^([a-zA-Z0-9-_]+)-([0-9]+)/$ /page.php?id=$1 [L]

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

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