Rewriting URL's with .htaccess

Status
Not open for further replies.

Mike

New member
Jun 27, 2006
6,779
114
0
50
On the firing line
Here's what I would like to do, and I think I've seen this before but I can't find it now.

Anyhow, I want to have a ton of URL's basically go to the same page. So, if someone goes to:

http //www.Domain.com/keyword-here.htm
http //www.Domain.com/second-keyword.htm
etc.

It will show still say that in the address bar, and as far as the SE's are concerned it is a new page, but I want to serve the same page. So, let's say that the page I want them to see is really at:

http //www.Domain.com/real-page.htm

Does that make sense? Or did I just talk myself in a circle?
 


You could do...

Code:
RewriteRule ^keyword-one.html?$ /master-page.html [L]
RewriteRule ^keyword-two.html?$ /master-page.html [L]
RewriteRule ^keyword-three.html?$ /master-page.html [L]

... but you'd have to add each one to the .htaccess file. The easiest way to do it would be something like...

Code:
RewriteRule ^modre/(.+[^\.html]).html?$ /master-page.html [L]

where any request for a .html file in the "modre" folder will get rewritten to the master-page.html. Either of those should work, but I haven't tested it.
 
  • Like
Reactions: Mike
Cool! Thanks I'll try that!

Chris, I'm not sure what taking twig in both hands is, but it sounds funny, so I ended up laughing!:D

/edit/ the first one works fine. I edited the second and couldn't get it to work.

Here's what I changed it to:
Code:
RewriteRule ^/(.+[^\.htm]).htm?$ /index.htm [L]
That didn't work, but this did:
Code:
RewriteRule ^/(.+[^\.html]).html?$ /index.htm [L]

So, that "L" makes a big difference! Thanks Kyle! +rep
 
Cool! Thanks I'll try that!

Chris, I'm not sure what taking twig in both hands is, but it sounds funny, so I ended up laughing!:D

/edit/ the first one works fine. I edited the second and couldn't get it to work.

Here's what I changed it to:
Code:
RewriteRule ^/(.+[^\.htm]).htm?$ /index.htm [L]
That didn't work, but this did:
Code:
RewriteRule ^/(.+[^\.html]).html?$ /index.htm [L]

So, that "L" makes a big difference! Thanks Kyle! +rep
the reason it didn't work the first time was because it was trying to rewrite the url that you were trying to rewrite it to, sending it into an infinate loop, since "index.htm" fits the ^/(.+[^\.htm]).htm?$ rule... that's why i put the "/modre/" in my example ;) .
 
Ahh! Makes perfect sense now. So this is the .htaccess file I'm using:

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

RewriteRule ^directory-name/(.+[^\.html]).html?$ /index.htm [L]

So, it rewrites:
Code:
http://domain.com/directory-name/file.html

To

Code:
http://www.domain.com/directory-name/file.html

Many thanks Kyle!
 
Status
Not open for further replies.