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.
Apache Web Server

Avatar of undefined
Last Comment
Amit Kumar

8/22/2022 - Mon
SOLUTION
Steve Bink

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Mark Bullock

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Amit Kumar

ASKER
I was wrong understanding RewriteRule and RewriteBase , right directory structure is very important.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23