Ad

Htaccess Redirect Incoming Url To Internal Page And Pass GET Variables

- 1 answer

I am trying to pass URLs to my site that contain numbers like this:

www.example.com/234

I want them to be rewritten like this:

www.example.com/view.php?id=234

My rewrite rules that are not working:

RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
RewriteRule ^([0-9]+)$ view.php?id=$1 [L]
Ad

Answer

Try it with only these 2 lines:

RewriteEngine on
RewriteRule ^([0-9]+)$ view.php?id=$1 [L]

Once you have that working, put in the conditionals. From what I understand line 3 is redirecting everything. Seems like an infinite loop to me.

Ad
source: stackoverflow.com
Ad