Solved

.htaccess redirect to other page with link info

Posted on 2013-06-15
6
312 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 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

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

Suggested Solutions

Title # Comments Views Activity
how do I get rid of "Multiple Choices The document name you requested" 3 340
PHP Error Settings 12 87
htaccess file 3 98
PHP: Insert Data into MySQL 5 68
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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

738 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