Forum Moderators: phranque
I'm in a bit of a dilemma here. I'm having trouble redirecting my dynamic url through htaccess, but I am able to do it using PHP.
Now the question is: does a htaccess 301 redirect do the same funtion as a PHP 301 redirect? Does it keep all ranks in the search engines, and are the search engines able to read the 301 redirect and eventually change the links just like any other htaccess redirect would do?
I see many people opt to using a htaccess 301 redirect rather than a php/python or any other 301 redirect that's available. Why is that? I know that when any visitor (being a bot or person) visits a website, the server always requests the .htaccess, is this the reason why? Wouldn't the server request the PHP redirect when a bot or person vists the website, and have the same results as the htaccess redirect?
PHP 301 redirect I'm using:
<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: [domain.com"...] );
?>
Thanks for your help in this matter.
If Apache can handle the redirect without having to pass the process further on down the line you are "saving" resource by not asking your server to continue processing the request, invoke the PHP module for processing, etc.
Yes, .htaccess files are read for every directory they reside in, for every request. So, if the process can be handled there, great. If not, let your script do the work.
I want to be able to redirect:
www.domain.com/index.php?network=something
to
www.domain.com/something
========================================
Here is what I used in htaccess:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^network=something$
RewriteRule ^index\.php$ /something [L]
I get this error:
The server is redirecting the request for this address in a way that will never complete.
.. how can I redirect using htaccess?
Here is what I did:
RewriteRule ^([^/]+)/?$ /index.php?network=$1 [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?network=([^&]+)\ HTTP/
RewriteRule ^index\.php$ [domain.com...] [R=301,L]
I get a Internal Server Error using the above. Do you, or anyone else know how I can do this redirect properly with htaccess?
Once again, I want to be able to redirect:
www.domain.com/index.php?network=something
to
www.domain.com/something
Err. A redirect should include the target domain name and [R=301].
Your second code has neither and therefore was for a rewrite, not a redirect.
.
In your third example, you have coded it with rewrites first and redirects last. That will expose internal filepaths to the outside world.
You need to place all the redirects before all of the rewrites in your code.
.
*** I want to be able to redirect: ***
*** www.domain.com/index.php?network=something ***
As coded it will only work for a URL like:
www.domain.com/index.php?network=something&
.
You should omit "index.php" from URLs.
This URL:
www.domain.com/?network=something&
is for the same resource, but is a Duplicate.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?network=([^&\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1? [R=301,L]
Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?network=([^&\ ]+)\ HTTP/
RewriteRule ^index\.php$ http://www.example.com/%1? [R=301,L]
Examine your server error log when you get a server error - It will ofthen tell you exactly what is wrong.
Jim
[edited by: jdMorgan at 6:07 pm (utc) on Aug. 20, 2008]