开发者

RewriteRule - take all urls with dash

开发者 https://www.devze.com 2023-01-02 07:44 出处:网络
I need to redirect all urls with dash to a specific page. For 开发者_JAVA百科example: site.com/this-url to site.com/page.php?url=this-url

I need to redirect all urls with dash to a specific page.

For 开发者_JAVA百科example:

site.com/this-url to site.com/page.php?url=this-url

RewriteRule

RewriteRule ^(.+-.+)$ page.php?url=$1

just hang http. No response.

What is wrong and how it can be done?


Try this instead, you may have an infinite loop.

RewriteCond $0 !^page\.php
RewriteRule ^(.+-.+)?$ page.php?url=$1 [L,B,QSA]

Now:

  • The RewriteCond avoids matching the rule if you already requested page.php
  • The QSA flags appends all the query parameters from the original request to the rewritten request
  • The B flag escapes the backreference $1 so that it can safely be used as a query paramater
  • The L flag is not strictly necessary, but avoids evaluating other rewrite rules when this one is matched


You may also try this option:

RewriteCond %{REQUEST_URI} !^page\.php
RewriteRule - page.php?url=%{REQUEST_URI} [L,B,QSA]
0

精彩评论

暂无评论...
验证码 换一张
取 消