Search code examples
apache.htaccessmod-rewriteseo

.htaccess affect other file url


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?


Solution

  • Try :

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