Forum Moderators: phranque
I want to redirect:
[tdfn.example.com...]
To:
[tdfn.example.com...]
I've tried doing this:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
Redirect permanent /index.php?goto=Frontier/Kazemon/kazemon [tdfn.example.com...]
That doesn't work. I know the question mark is a quantifier in mod_rewrite, so I then tried doing this:
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
Redirect permanent /index.php\?goto=Frontier/Kazemon/kazemon [tdfn.example.com...]
RewriteRule ^(.*)/$ index.php?goto=$1
And that doesn't work either. Please help me, this is really driving me crazy, such a simple problem yet so frustrating! Yet redirects work fine if the page it redirects from doesn't have a parameter. -sigh- Any help would greatly be appreciated.
[edited by: jdMorgan at 5:27 pm (utc) on July 16, 2006]
[edit reason]
[1][edit reason] No URLs, please. See TOS. [/edit] [/edit][/1]
In order to test and/or manipulate query strings, you'll need to use RewriteCond %{QUERY_STRING} followed by a RewriteRule that examines only the local URL-path of the request. For example:
RewriteCond %{QUERY_STRING} ^goto=Frontier/Kazemon/kazemon$
RewriteRule ^index\.php$ http://tdfn.example.com/Frontier/kazemon/ [R=301,L]
[edited by: jdMorgan at 5:32 pm (utc) on July 16, 2006]
This is the URL that shows up after the redirect:
[tdfn.example.com...]
It redirects to the right page but it looks... odd with the redundant query string. More importantly will this affect search engine ratings? Will the search engine index that long URL? Any help would greatly be appreciated again... it really would.
RewriteCond %{QUERY_STRING} ^goto=Frontier/Kazemon/kazemon$
RewriteRule ^index\.php$ http://tdfn.example.com/Frontier/kazemon/? [R=301,L] I can't test it at the moment, but I'm pretty sure that's what someone here told me and I'm pretty sure that's still working on a site where I implemented that.
My current .htaccess file:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^goto=Frontier/Kazemon/kazemon$
RewriteRule ^index\.php$ [tdfn.example.com...] [R=301,L]
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)/$ index.php?goto=$1
RewriteCond %{HTTP_HOST} ^www\.tdfn.example\.com
RewriteRule ^(.*)$ [tdfn.example.com...] [R=301,L]
# Redirects
Redirect permanent /Tdfn [tdfn.example.com...]
RewriteRule ^Tdfn/Downloads/amvs.htm [tdfn.example.com...] [R=301,L]
RewriteRule ^Tdfn/Frontier/epguide.htm [tdfn.example.com...] [R=301,L]
RewriteRule ^Downloads/video.htm [tdfn.example.com...] [R=301,L]
# Custom 404 Page
ErrorDocument 404 /index.php?goto=error
If I may ask another question, if I can't redirect my old pages should I make them PHP pages with the HTTP header #403 - Gone?
So, is it that the new rule almost worked, but stopped working when you added the trailing question mark? Or the whole .htaccess file doesn't work, or you get a server error, or what?
Tell us how you tested:
It's very difficult to remote-diagnose these problems, and you can increase the chances of getting a useful answer by being very thorough and specific.
[added]
Your code is disorganized, and this may lead you to misunderstand how it works. Here is your code re-arranged to show the order that the directives will execute on a typical server. Note that directives belonging to different Apache modules will execute in the order shown regardless of their order in your code.
# Apache core directives - declare custom 404 Page
ErrorDocument 404 /index.php?goto=error
#
# mod_aliasdirectives - redirects
Redirect permanent /Tdfn http://tdfn.example.com/
#
# mod_rewrite directives - internal rewrites and external redirects
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
#
RewriteCond %{QUERY_STRING} ^goto=Frontier/Kazemon/kazemon$
RewriteRule ^index\.php$ http://tdfn.example.com/Frontier/kazemon/? [R=301,L]
#
RewriteRule ^(.*)/$ index.php?goto=$1
#
RewriteCond %{HTTP_HOST} ^www\.tdfn.example\.com
RewriteRule ^(.*)$ http://tdfn.example.com/$1 [R=301,L]
#
RewriteRule ^Tdfn/Downloads/amvs.htm http://tdfn.example.com/Downloads/amvs/ [R=301,L]
RewriteRule ^Tdfn/Frontier/epguide.htm http://tdfn.example.com/epguide01/ [R=301,L]
RewriteRule ^Downloads/video.htm http://tdfn.example.com/downloads/ [R=301,L]
Jim
Thank you so much for your help jdMorgan, you have my most sincerest and deepest gratitude. ^^
Yes I did have some confusion on how Apache executed it's directives within the .htaccess file. Thanks for the clarification, again very much appreciated.