Link to home
Start Free TrialLog in
Avatar of Amit Kumar
Amit Kumar

asked on

RewriteRule does not work with leading / in pattern url or target url

I am using Ampps on mac, I see if I place forwarding slash either in patternurl or in target url , in any case it does not work

#no 404 error with below line if there is no forwarding slash with any pattern
RewriteRule ^main/(.*)$ index.php?term=$1 [L]
#but 404 error with any of these two
RewriteRule ^main/(.*)$ /index.php?term=$1 [L]
RewriteRule ^/main/(.*)$ index.php?term=$1 [L]
#and more surprise, if I place any forwarding slash in any pattern but use "RewriteBase /" does not work in this case too , below with error:
RewriteBase /
RewriteRule ^main/(.*)$ index.php?term=$1 [L]


though I found lot of examples over internet using forwarding slashes , I do not know whats going wrong , but again I am surprised when I run wordpress on localserver (AMPPS) , I check its htaccess file as below:


RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

I see /index.php works here (there is no 404 error at all), what I am doing wrong.
SOLUTION
Avatar of Steve Bink
Steve Bink
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amit Kumar
Amit Kumar

ASKER

I was wrong understanding RewriteRule and RewriteBase , right directory structure is very important.