Apache rewrite regex
Hi all,
I have simple blog I created myself. I am using mod rewrite to redirect all to a php file. But I have links in google like kdelchev.com/?p= or kdelchev.com/?cat=7 How can I match it with regular expression? I try with variants of ^([^/\?]+)/$ but with no success. The desired result is to redirect such addresses to kdlechev.com or to 301 page |
Hi,
You can use the following: Code:
RewriteEngine on |
It also helps if you can see what's going on, try turning on logging -
Code:
RewriteLog /var/log/httpd/mysite_rewrite.log |
One more question: How can I redirect all invalid addresses like http://kdelchev.com/?cat=7 to http://kdelchev.com/ i.e. to match everything that begin with ? after the /
|
Quote:
Regards |
Thanks for the reply, bathory
It work for ?cat=7 but didn't work for ?cat= and other invalid addresses. I added the rule and the condition exactly, but the ?cat string stay at the end of the address and no redirect is made. The rule is at the beggigning of the .htaccess file. I added [L] just in case the condition is overridden by another rule, but that didn't help. I also try toescaspe the questiuon mark: [code]RewriteCond %{QUERY_STRING} ^(.*)= RewriteRule ^(.*)$ /\? [R=301][L][code] Maybe there is some other options I miss... Anyway, that works, but it will be better to be able to redirect all invalid addresses. |
I guess you prepend the "RewriteEngine On" directive.
Also make sure that .htaccess files are read by apache. This is done by Code:
AllowOverride All |
Yes, I use RewriteEngine on. The htaacess file is read by apache. All changes I made make differencies.
Let's stay that way for now. Thank you very much fot the help! |
All times are GMT -5. The time now is 04:22 AM. |