views:

82

answers:

2

I need to redirect all urls with dash to a specific page.
For 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?

A: 

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
Artefacto
A: 

You may also try this option:

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