1

I decided to use mod_rewrite to make my URLs look better. I created very simple rules:

RewriteEngine on RewriteBase / RewriteRule ^(profile|contact|help|events|account|logout)/?$ index.php?p=$1 [NC] RewriteRule ^home/?$ index.php [NC] RewriteRule ^PlaceOrder/([0-9]+)/?$ index.php?p=mos&gc=$1 [NC] 

It almost works well but it doesn't. So for example, [NC] is supposed to make it case-insensitive. However, for some reason, when I type for example localhost/Help in the browser, for some strange reason, it redirects to home page. Another issue is with the last rule. If I type in localhost/PlaceOrder/1 it works as expected and opens index?p=mos&gc=1. But after that if I click on, for example, Account button, the browser uses this URL: localhost/PlaceOrder/account. Which is wrong. It should only use localhost/account. Why is it adding that sub-directory in there? It is only happening after the last rule is used. Prior to using the last rule, all links work well.

1
  • Are you not getting $_GET['p'] = Help in index.php for localhost/Help? Commented Feb 1, 2015 at 8:54

1 Answer 1

1

I'm going to guess that the localhost/Help isn't because of the rules and because of something in your index.php script. There's nothing those rules do that could possibly rewrite Help to the home page.

The second issue is a matter of a relative vs absolute URL issue. You're probably using relative links in your pages and because you've changed your relative URL base (which would be /PlaceOrder/ all relative links will have that prepended to it. You need to either change all your links to absolute URLs (they'd start with a /) or add this to your page's header:

<base href="/" /> 
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't that what RewriteBase is for?
@user2395238 nope, that's not what RewriteBase does at all: stackoverflow.com/questions/21347768/… It has nothing to do with how your browser interprets the URL base

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.