Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
Make post title as a slug in url by mod rewrite

I have a url:

I want to rewrite it as using mod rewrite

I am using following rewite_rule:

RewriteRule ^([0-9]+)/([0-9]+) $$1&p=$2   [L]

but it is not working. If I type it redirects to url. Please help me in this issue. Thanks

share|improve this question

migrated from Jun 22 '11 at 17:22

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Caleb, Chopper3 Jun 24 '11 at 7:41

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

i missread the question, deleting my answer – Ibu Jun 22 '11 at 6:36
but you said that its redirecting to the correct place?!! what is the problem with the redirect? – Ibu Jun 22 '11 at 6:37
@lbu Its being reverse redirect. I want like directory structure in url and want to get rid from perimeters – Sohail Jun 22 '11 at 6:39
up vote 0 down vote accepted

The prblem in your approach is

  1. ^([1-9]+) the URI starts with / - your telling the rule to check for some digits without /
  2. There could be zeros in your URL so having 1-9 will not allow you to have zero.

Try this:

RewriteRule ^/([0-9]*)/([0-9]*)$1&p=$2   [L]

You can validate your rewrite-rule here -

share|improve this answer

If it's about the _redirect_, then remove the http://... prefix from the target part.

RewriteRule ^(\d+)/(\d+)$  details.php?var=$1&p=$2   [L]

Make this the first rule.

Also keep in mind that you have to adapt your application to actually generate /123/456 urls. The rewriterule only works on incoming requests, it does not alter pages.

share|improve this answer
It works but images are not showing on the page. – Sohail Jun 22 '11 at 6:51
If the page has a new virtual URL, then the relative references stop to work. The easy workaround is to embed <base href="/index"> in the <head> of your pages. – mario Jun 22 '11 at 6:54
your are really super Mario. Thanks buddy – Sohail Jun 22 '11 at 7:04

Include 0 in the regular expression:

RewriteRule ^/([0-9]+)/([0-9]+)/?$$1&p=$2   [L]

The reverse would be:

RewriteCond %{QUERY_STRING} ^var=([0-9]+)\&p=([0-9]+)$ 
RewriteRule ^details\.php$ [R=301,L]
share|improve this answer
problem is still persisting. – Sohail Jun 22 '11 at 6:35
Added the reverse of the rewrite, in case you want that instead. – aorcsik Jun 22 '11 at 6:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.