Ad

.htaccess Affect Other File Url

- 1 answer

I am trying to make .htaccess rule not affect other file url

example my .htaccess rule is

RewriteEngine On
RewriteRule ^([^/]*)$ /tr/hp.php?q=$1 [L]

my site url is

mydomain.com/keywords

everything working good on keywords but when I try to open robots.txt

mydomain.com/robots.txt

OR

mydomain.com/images.jpg

any other file url

redirect on /tr/hp.php?q=filename

which .htaccess Rewrite Rule works on both?

Ad

Answer

Try :

RewriteEngine On
#--exclude real directories
RewriteCond %{REQUEST_FILENAME} !-d
#--and files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /tr/hp.php?q=$1 [L]
Ad
source: stackoverflow.com
Ad