1

I have a url of the form:

www.example.com/r/abc/1234

that I want to rewrite to:

www.example.com/r.php?deb=abc&id=1234

And another url:

www.example.com/r/12bcd-qsqs-343-wdwd/1234

which should be rewritten to:

www.example.com/r.php?abc_id=12bcd-qsqs-343-wdwd&id=1234

Both of these rule should be handled by .htaccess. Any suggestions?

hakre
  • 193,403
  • 52
  • 435
  • 836
Prathamesh mhatre
  • 1,015
  • 5
  • 17
  • 32
  • Pass all into a script of your own and than inside that PHP script process the URI as one parameter. That is much more less specific to the webserver you are running on and more flexible. This normally only needs a single or very few rules. Compare: [symfony2 rewrite rules .htaccess app.php](http://stackoverflow.com/questions/11149526/symfony2-rewrite-rules-htaccess-app-php) – hakre Aug 28 '12 at 07:53

2 Answers2

1

Try something like :

RewriteRule (.*)/(.*)/(.*)$ path_to_php_files/$1.php?deb=$2&id=$3 [QSA,L,NC]

Unfortunately with this rule, you would have the first $_GET parameter always deb and I hope you have the DirectoryIndex set up corectly. I do not think that for

www.example.com/r/abc/1234
www.example.com/r/12bcd-qsqs-343-wdwd/1234

you can delivrer the abc and 12bcd-qsqs-343-wdwd to 2 different $_GET parameters if you have dynamic links.

Cosmin
  • 1,482
  • 12
  • 26
1

Both the URIs that you want to redirect look similar except that 2nd one has hyphens - in first query parameter.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^r/([^-]+)/(.+)/?$ r.php?deb=$1&id=$2 [L,QSA]

RewriteRule ^r/([a-z0-9-]+)/(.+)/?$ r.php?abc_id=$1&id=$2 [L,QSA,NC]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Thanks for the help with little changes I have made it work, But now the problem is its working on my localhost but when I transferred it on the server were I am running virtualhost Its not working can you help ? – Prathamesh mhatre Aug 28 '12 at 09:14
  • On the server make sure .htaccess is enabled and then if .htaccess is correctly paced in DOCUMENT_ROOT directory. If everything is right then add `R` flag in above 2 RewriteRule lines to see what is the final URI on server. – anubhava Aug 28 '12 at 09:39
  • Thanks a lot :) Is there some how I can keep contact with you any social site or anything ? – Prathamesh mhatre Aug 28 '12 at 09:52
  • You're welcome. Here is LinkedIn Contact: http://www.linkedin.com/in/anubhavasrivastava – anubhava Aug 28 '12 at 09:59