Solved

.htaccess redirect to other page with link info

Posted on 2013-06-15
6
311 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
  • 3
  • 3
6 Comments
 
LVL 50

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 50

Expert Comment

by:Steve Bink
ID: 39251491
Make sure you have mod_rewrite enabled.  Are you using any other rules?
0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 

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 50

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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Suggested Solutions

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…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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