Solved

.htaccess redirect to other page with link info

Posted on 2013-06-15
6
313 Views
Last Modified: 2013-06-17
Hi,
I want to redirect pages that are not found to a redirect_page.php using .htaccess but I want to also process the link information.

For example if I have a link to the following pages that don't exist http://www.mywebsite.com/213 or http://www.mywebsite.com/page=454
how do I pass the '/213' & '/page=454' part to my redirect_page.php page?

ErrorDocument 404 http://www.mywebsite.com/redirect_page.php
0
Comment
Question by:sabecs
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 39250558
You'll have to use a rewrite to do this.  Something like:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule (.+) /redirect_page.php?uri=$1 [QSA]

Open in new window

0
 

Author Comment

by:sabecs
ID: 39250704
Thanks routine for your help, but when I tried your code I receive an Internal Server Error?
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 39251491
Make sure you have mod_rewrite enabled.  Are you using any other rules?
0
Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

 

Author Comment

by:sabecs
ID: 39252109
Thanks  routinet, this is what I have so in my .htaccess.

#SetEnv PHPRC /home/mywebsite/public_html
Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteCond %{REQUEST_URI} Details
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /index.php?page=$1&id=$2&new_page_title=$3 [L]
RewriteRule ([0-9]+)(.*)\.html$ index.php?page_id=$1 


RedirectMatch permanent ^/show/?$  http://www.mywebsite.com.au/showme.php
RedirectMatch permanent ^/showme/?$  http://www.mywebsite.com.au/showme.php


RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule (.+) /redirect_page.php?uri=$1 [QSA]

Open in new window

0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 39253773
I don't see anything obvious there.  Try turning on your RewriteLog...perhaps mod_rewrite can provide some feedback about the application of these rules.

Note that you have to turn on the log in your server conf files, not .htaccess.
0
 

Author Closing Comment

by:sabecs
ID: 39254903
Thanks routine, seems to be working now, not sure what I missed...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

691 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