Link to home
Start Free TrialLog in
Avatar of sabecs
sabecs

asked on

htaccess - redirect text links that don't exist

Hi,
is it possible to use .htaccess to redirect text links that don't exist to specific page.

for example I would like
"Online Shop" to redirect to http://www.mywebsite.com/index.php?page_id=154 
"Contact" to redirect to http://www.mywebsite.com/index.php?page_id=12 

Thanks in advance for your feedback.
Avatar of Amar Bardoliwala
Amar Bardoliwala
Flag of India image

Hello sabecs,

It is possible to redirect text links that don't exist to a specific page.

Go through following links. It will help you to learn about rewrite urls.

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

http://www.evolt.org/ultimate_htaccess_examples

http://www.webweaver.nu/html-tips/web-redirection.shtml

Hope this will help you.

Thank You.

Amar Bardoliwala.
ASKER CERTIFIED SOLUTION
Avatar of trackstudio10
trackstudio10
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs
sabecs

ASKER

Thanks for your help and feedback,
I have a content management system and would like to make it easier for users to add text links from one page to another instead of creating links to a page using the page ID stored in database.

I would like to use
<a href="Online Shop">Online_Shop</a>
instead of
<a href="index.php?page_id=154">Online Shop</a>

I was therefore thinking of running a PHP script every time a page is added or changed via the CMS and match the page name with the page id, then update my .htaccess file with the new Rewrite Rules.  

RewriteRule Online Shop index.php?page_id=154
RewriteRule Gallery index.php?page_id=42

It looks like it will work except for a problem with spaces (or more than one word in page name), so above links to “Gallery” page works but not to “Online Shop”

Not sure if it’s better to modify the .htaccess file or use a separate page as mentioned by Ray?
You are right about impossibility of having url with space in htaccess.
In terms of SEO both offered ways are equivalent.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sabecs

ASKER

Thanks you for your help, I will have a think about which way to go, that is using .htaccess file or a seperate "missing page" handler.

Also, as an FYI, another member mentioned that you can escape the space with backslash in the .htaccess file which works great.
RewriteRule Online\ Shop index.php?page_id=154