fermium
asked on
.htaccess url rewrite
I need a .htaccess file which would do the following:
Rewrite
http://www.domain.com/somedomain.com
to
http://www.domain.com/check.php?domain=somedomain.com
It should only rewrite if a valid domain name is provided.
It should not cause problems with other dirs like http://www.domain.com/images/ e.t.c.
Plz help.
Rewrite
http://www.domain.com/somedomain.com
to
http://www.domain.com/check.php?domain=somedomain.com
It should only rewrite if a valid domain name is provided.
It should not cause problems with other dirs like http://www.domain.com/images/ e.t.c.
Plz help.
ASKER
@insoftservice:
No that does not work.
Best thing that works till now is - RewriteRule ^([a-zA-Z0-9_-]+)$ check.php?domain=$1
However it is even rewriting for non-domain: http://www.domain.com/images
So a little tweak is required to only rewrite for valid domain name. domain with extension.
No that does not work.
Best thing that works till now is - RewriteRule ^([a-zA-Z0-9_-]+)$ check.php?domain=$1
However it is even rewriting for non-domain: http://www.domain.com/images
So a little tweak is required to only rewrite for valid domain name. domain with extension.
hope this helps
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([A-Za-z0-9-]+)/?$ check.php?domain=$1 [NC,L]
ASKER
@shinuq:
Sorry that does not work at all.
http://www.domain.com/somedomain.com is showing: 404 Not Found
Sorry that does not work at all.
http://www.domain.com/somedomain.com is showing: 404 Not Found
RewriteRule ^([A-Za-z0-9-]+)/?$ http://www.domain.com/check.php?domain=$1 [NC,L]
May be this should work
May be this should work
ASKER
@shinuq:
Sorry that also does not work.
http://www.domain.com/somedomain.com is showing: 404 Not Found
http://www.domain.com/ is working alright.
Sorry that also does not work.
http://www.domain.com/somedomain.com is showing: 404 Not Found
http://www.domain.com/ is working alright.
Much shorter and an alternative is
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /check.php?domain=$1 [L]
RewriteEngine On
RewriteRule ^([^/]*)\.html$ /check.php?domain=$1 [L]
ASKER
@shinuq:
Sorry that also does not work too.
http://www.domain.com/somedomain.com is rewriting to - http://www.domain.com/check.php?domain=check.php
Sorry that also does not work too.
http://www.domain.com/somedomain.com is rewriting to - http://www.domain.com/check.php?domain=check.php
OK, what are the possible urls that you accessing. I am trying with another example,
Does your url have only the .com as the url end.
RewriteRule ^([^/.]+)/?$ /check.php?domain=$1 [L]
Does your url have only the .com as the url end.
RewriteRule ^([^/.]+)/?$ /check.php?domain=$1 [L]
ASKER
Ok this is the thing that works now:
RewriteEngine on
RewriteRule ^$ index.php [L]
RewriteRule ^index.php$ index.php [L]
RewriteRule ^domains.php$ domains.php [L]
RewriteRule ^check.php$ check.php [L]
RewriteRule ^style.css$ style.css [L]
RewriteRule ^([a-zA-Z0-9-.]+)$ check.php?domain=$1
However code looks clumsy. Is it possible to optimize it?
RewriteEngine on
RewriteRule ^$ index.php [L]
RewriteRule ^index.php$ index.php [L]
RewriteRule ^domains.php$ domains.php [L]
RewriteRule ^check.php$ check.php [L]
RewriteRule ^style.css$ style.css [L]
RewriteRule ^([a-zA-Z0-9-.]+)$ check.php?domain=$1
However code looks clumsy. Is it possible to optimize it?
ASKER
This works better:
RewriteEngine on
RewriteRule ^([a-z]+)\.php$ $1.php [L]
RewriteRule ^([a-z]+)\.css$ $1.css [L]
RewriteRule ^([a-zA-Z0-9-.]+)$ check.php?domain=$1
Any more optimization?
RewriteEngine on
RewriteRule ^([a-z]+)\.php$ $1.php [L]
RewriteRule ^([a-z]+)\.css$ $1.css [L]
RewriteRule ^([a-zA-Z0-9-.]+)$ check.php?domain=$1
Any more optimization?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wow you are a Genius.
#RewriteRule ^/(.*)/?$ check.php?domain=$1
RewriteRule (.*)/?$ check.php?domain=$1
chk this one