Question

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

Was it helpful?

Solution

You have 2 problems:

  1. You are matching very generic .*\..* pattern in first rule which will make 2nd rule defunct.
  2. You are not using 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]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top