Forum Moderators: phranque

Message Too Old, No Replies

Rewriting URL to point at subfolder

rewriting urls

         

luke64

9:19 pm on May 30, 2008 (gmt 0)

10+ Year Member



My problem: I'm currently running a virtual host, in which my website uses site relative hyperlinks, e.g. /properties.php, /contact.php, these links work fine, but as expected if I move my website files to say htdocs/mysite/ the links no longer work as the root is now localhost.

I'm trying to create a rewrite rule that adds the sub directory mysite to the url so it becomes /mysite/properties.php etc. - I've tried using using the example at [roshanbh.com.np...] and the rule below:

#RewriteRule \/(.+)$ mysite/$1

all unfortunately to no avail - can anyone shed some light on my problem!?

Regards,

Luke

[edited by: luke64 at 9:29 pm (utc) on May 30, 2008]

luke64

9:20 pm on May 30, 2008 (gmt 0)

10+ Year Member



I should add the rewrite rule is stored in a .htaccess file in the mysite directory.

jdMorgan

9:28 pm on May 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have any other working rewriterules?

The rule you show is commented-out, and so will not be executed.
It also contains no provision to avoid rewriting requests for /ppg/foo to /ppg/ppg/foo/ to /ppg/ppg/ppg/foo, etc. and so it will loop until the server reaches its "internal redirection limit" and gives up.

Jim

luke64

9:36 pm on May 30, 2008 (gmt 0)

10+ Year Member



This was the other rule I was experimenting with based on the example given in the link (doesn't work at the moment)

RewriteCond %{HTTP_HOST} ^localhost$ [OR]
RewriteCond %{HTTP_HOST} ^www\.localhost$
RewriteCond %{REQUEST_URI} !^/localhost/
RewriteRule \/(.+)$ mysite/$1

I don't think I'm approaching capturing the existing url correctly for me to then insert the sub directory into the url?

jdMorgan

10:28 pm on May 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Again, do you have any other working rewriterules? -- It is important to establish whether you've got mod_rewrite enabled and working, making this a problem with a single rule, or whether your mod_rewrite setup is incorrect, meaning that no rule will work.

Mod_rewrite is details -- all details, and lots of details. So discussion, questions and instructions in this forum must be written and read very carefully. Attention to detail determines success or failure.

Jim

luke64

11:19 pm on May 30, 2008 (gmt 0)

10+ Year Member



My apologies, this is the entire contents of the .htaccess file I'm currently using (stored at the htdocs level), there's no other .htaccess file in the mysite subdirectory.

You'll notice I've changed the rewrite rule I'm using again - just testing different examples I'm finding...

Code:

# Enable mod_rewrite
RewriteEngine on

RewriteBase /

#RewriteCond %{HTTP_HOST} localhost
RewriteCond %{REQUEST_URI} !mysite/
RewriteRule ^(.*)$ /mysite/$1 [R=301,L]

---------------------------------
Relevant settings from httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so

<Directory "C:/xampp/htdocs/mysite/">
AllowOverride All
</Directory>

jdMorgan

11:39 pm on May 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have asked the same direct question twice, with no answer. I cannot help you. Sorry.

Jim

luke64

1:39 pm on May 31, 2008 (gmt 0)

10+ Year Member



Again my apologies, I didn't make myself very clear in my previous message - the code included was the entire contents of my .htaccess file - I have no other working rewrite rules.

Luke

Also the rewrite condition #RewriteCond %{HTTP_HOST} localhost is not commented out as my earlier message described.

jdMorgan

2:12 am on Jun 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First steps, then...

Try this:


RewriteEngine on
RewriteRule ^foo\.html$ http://www.google.com/ [R=301,L]

Request the page "/foo.html" from your server. Did you end up at google?

If not, add a line:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^foo\.html$ http://www.google.com/ [R=301,L]

Does that work now?

Jim