I have a website wich is based on a searchpage, which shows a list, and next is a detail page of the items.
if visitors use rootdomain.com/searchterm
, should be redirected to rootdomain.com/index.php?keyword=searchterm
.
I had that working now for the details rootdomain.com/detail/productname
, should be redirected to rootdomain.com/detail.php?name=productname
and here I fail...
I keep getting redirected to index.php with my $1 as 'detail/productname'
this is my .htacces
so far:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/detail/(.*)$ detail.php?name=$1 [L,QSA] -> L here doesn't work either.
RewriteRule ^(.*)$ index.php?keyword=$1 [L,QSA]
Update
Ok, so I am very close now
Problem was that the rewrite condition only is valid for the next rule so I have to repeat that apparantly, I also added ignore detail.php in the first condition, because my redirect on detail got redirected again to index. now for some reason my condition for -f doesn't seem to work on detail/ all my css and images are not working. what is best way to exclude them
RewriteEngine on
RewriteCond $1 !^(index\.php|detail\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^detail/(.*)$ detail.php?name=$1 [L,QSA]
RewriteCond $1 !^(index\.php|detail\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?keyword=$1 [L,QSA]
Update 2
So I got it to work.. But I guess this is not the shortest way to do it. So if anyone is interested feel free to make this shorter.
RewriteEngine on
RewriteCond $1 !^(index\.php|detail\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^detail/(images|css|js)/(.*)$ $1/$2 [L,QSA]
RewriteCond $1 !^(index\.php|detail\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^detail/(.*)$ detail.php?name=$1 [L,QSA]
RewriteCond $1 !^(index\.php|detail\.php|resources|robots\.txt|\.png)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?keyword=$1 [L,QSA]