Forum Moderators: phranque

Message Too Old, No Replies

rewrite help to keep url

         

hijinks

1:37 am on Jun 7, 2005 (gmt 0)

10+ Year Member



I have this url.. i want to keep using mod_rewrite. They come in like this

[profile.domain.com...]

The rule works and sends them to

[domain.com...]

Here is the rule

RewriteEngine On
RewriteRule ^(.*)$ [domain.com...] [L]

Now It will not keep the [profile.domain.com...] in the browser window like i want.. is there a way to stop this re-direction with the browser?

jdMorgan

4:51 am on Jun 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hijinks,

Welcome to WebmasterWorld!

By specifying a canonical URL in your substitution, you have forced an external redirect. Since you did not specify which type you wanted by using the [R] flag, mod_rewrite will default to a 302 redirect.

The solution is either simple or very simple, depending on whether this code is for use in .htaccess or in httpd.conf. Either way, you use a path relative to the server root rather than a canonical URL, in order to specify an internal rewrite rather than an external redirect:

.htaccess:


# Prevent .htaccess recursion if index.php is requested
RewriteCond $1 !^index\.php$
# else do the rewrite
RewriteRule (.*) /index.php?option=profile&user=$1 [L]

httpd.conf:

RewriteRule ^/(.*) /index.php?option=profile&user=$1 [L]

Jim

hijinks

2:15 pm on Jun 7, 2005 (gmt 0)

10+ Year Member



when i do this

RewriteRule ^/(.*) [theblogring.com...] [L]

I get a 404.. now i can't do /index.php.. since its on a complete different subdomain

it tries to load profile.domain.dom/index.php

jdMorgan

2:00 am on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, your rule is invalid. Did you try my suggestions?

And again, is your code in .htaccess or httpd.conf? It makes a difference.

Jim

hijinks

2:53 pm on Jun 8, 2005 (gmt 0)

10+ Year Member



ya i did.. with yours i get a 404 on the username.. its in a htaccess file

jdMorgan

5:33 pm on Jun 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, here's the full code block. You'll need to have the first two directives somewhere in your Web-root directory .htaccess file preceding the last two. The first two directives should appear only once in the file.

Furthermore, it is possible but unlikely that adding the Options directive will cause a 500-Server Error. If this happens, delete that directive. But either the FollowSymLinks or SymLinksIfOwnerMatch option must be set in your httpd.conf or .htaccess file in order to enable mod_rewrite.


Options +FollowSymLinks
RewriteEngine on
#
# Prevent .htaccess recursion if index.php is requested
RewriteCond $1 !^index\.php$
# else do the rewrite
RewriteRule (.*) /index.php?option=profile&user=$1 [L]

Another possibility is that your account's physical pathname is aliased. In that case, your error log of the 404 event should show the full path that the server was attempting to access. By correcting the code above to account for the aliased path, you should be able to get it to work. You do this by using the RewriteBase [httpd.apache.org] directive.

Jim