Reputation: 131
For a domain marketplace, I want to rewrite some urls and redirect my old pages (in a directory) to new pages directly.
For "rewrite url", I used these codes:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(.*\.php)?$
RewriteCond %{REQUEST_URI} !^/(.*\.htm)?$
RewriteCond %{REQUEST_URI} !^/(.*\.html)?$
RewriteCond %{REQUEST_URI} !^/(.*\.shtml)?$
RewriteCond %{REQUEST_URI} !^/whois/$
RewriteRule ^(.*\.*)$ /details.php?domain=$1 [qsa,l]
RewriteRule ^whois/([^/]*)$ /whoisrequest/whois.php?whois=$1 [L]
For example http://mydomain.com/test.com
url rewrite like http://mydomain.com/details.php?domain=test.com
- It's okey.
Problem: But at the same time, for rewriting whois url (http://mydomain.com/whois/test.com
) or redirecting old pages (like http://mydomain.com/domains/123/test.com
) to new ones (like http://mydomain.com/test.com
) rewriting to …details.php?domain=…
How should I handle these rules:
If http://mydomain.com/test.com
, then rewrite http://mydomain.com/details.php?domain=test.com
(only on main site and include "."[dot] - It can be like anything.anything )
If http://mydomain.com/folder1/
or more folders, then “. (dot) is not important’, will not rewrite.
Besides, redirect 301 http://mydomain.com/domains/123/test.com
to http://mydomain.com/test.com
Upvotes: 1
Views: 73
Reputation: 785316
You have 2 problems:
.*\..*
pattern in first rule which will make 2nd rule defunct.RewriteCond %{REQUEST_FILENAME} !-f
to avoid rewriting for real files/directories.Have your rules like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^whois/([^/]+)/?$ /whoisrequest/whois.php?whois=$1 [L,QSA]
RewriteRule ^([^/]+)/?$ /details.php?domain=$1 [L,QSA]
Upvotes: 1