mod_rewrite from base of a domain
I'm not sure if this is possible but I want to use mod_rewrite like so:
http://abc.com/something => http://abc.com/script.php?q=something
This doesn't work:
Options +FollowSymLinks
RewriteEngine on
RewriteRule /(.*)$ /script.php?q=$1
Is it possible to do?
Edit: I should mention mod_rewrite is working fine when I use this for example:
Options +FollowSymLinks
RewriteEngine on
RewriteRule script/(.*)$ /script.php?q=$1
Edit Again: http://emailsms.me/redirect.php?id=abc
Using this:
RewriteEngine on
RewriteRule ^([A-z]{1,})$ /redirect.php?q=$1
So theoretically http://emailsms.me/abc should be outputting abc (all it does is echo the input at the moment). but instead I get a 404 error.
Update: It seems as though Options +FollowSymLinks is causing the problem here. If I comment it out I get a 404 error but when its there and I put anything (I mean anything even a #) I get this error 开发者_开发技巧in my logs:
[Fri Oct 14 02:20:26 2011] [alert] [client 1.2.3.4] /home/me/redirects/.htaccess: Illegal option #
Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /script.php?q=$1 [L,QSA]
You probably don't want the trailing forward slash in your rewrite rule, and you need to check that the requested file doesn't exist (the 2 RewriteCond lines) otherwise you'll get a 500 Server error because the rewrite loops (/script.php will ALWAYS match ^(.*)$ and get rewritten again). Note that if you don't have a /script.php file, you'll get a 500 error because the rewrite will loop.
It sounds like you're doing this from .htaccess, rather than vhost configuration. In that case you must lose the first / in your RewriteRule.
You could try something like:
RewriteEngine on
RewriteRule ^([A-z]{1,})$ /script.php?q=$1
It crashes with the (.*) as you can see
精彩评论