• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 58
  • Last Modified:

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.
0
Amit Kumar
Asked:
Amit Kumar
2 Solutions
 
Steve BinkCommented:
Are these rules in a host or directory context?  Are any of these files inside an aliased directory structure?  Have you tried turning on your RewriteLog to see what is happening?
0
 
Mark BullockQA Engineer IIICommented:
I used the following
RewriteRule ^main/(.*)$ /test.html?term=$1 [r=301,L]

I requested
http://host.example.com/main/blah
and got redirected to
http://host.example.com/test.html?term=blah
0
 
Amit KumarAuthor Commented:
I was wrong understanding RewriteRule and RewriteBase , right directory structure is very important.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now