htaccess rewrite to add subdirectory name and .htm to request

Posted on 2008-01-29
Medium Priority
Last Modified: 2008-03-06
In those instances when a page is called by a four-digit number, I need a rewrite that adds a subdirectory name and ".htm" to the call, like this:

www.videojobshop.com/2345 > videojobshop.com/job_videos/2345.htm


videojobshop.com/2345 > videojobshop.com/job_videos/2345.htm

Note that the subdirectory "job_videos" has been added and ".htm" has been added

I need to be careful that this rewrite only affects urls that look like this - www.domain.com/5678 - so I need a check for a four-digit number.
Question by:alanjacobson

Accepted Solution

BenMorel earned 1000 total points
ID: 20773905
Just put this code in a .htaccess file at the root of your website, or put it into your website's <VirtualHost> container in httpd.conf (apache config file) if apache doesn't allow such a .htaccess use :

RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]{4})$ job_videos/$1.htm [QSA,L]

It will work with both domains, with and without www if both point to the same location (or are in the same <VirtualHost> container). This should be already the case :)
It will work only for these domains.


Author Comment

ID: 20774066
You rule! Excellent!

Thank you so much!

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
What You Need to Know when Searching for a Webhost Provider
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
If you are looking for an automated solution for backup single or multiple Office 365 user mailboxes to Outlook data file, then you can use Kernel Office 365 Backup & Restore tool. Go through the video to check out the steps to backup single or mult…
Suggested Courses

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question