Forum Moderators: phranque

Message Too Old, No Replies

ModRewrite not picking up url values

         

swanweb

7:28 pm on Aug 14, 2007 (gmt 0)

10+ Year Member



We have just had some issues with Apache & PHP, and now out .htaccess rules are not working quite right, it is diverting to the correct page, however it does not seem to be passing over the values, we use a keyword rich url like:

[someurl.com...]
[someurl.com...]

This is loading the correct page, but isnt passing the Dubai, or Turkey bit, and its the same with the other types of urls we have, heres part of our .htaccess file:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME}!-f

RewriteCond %{REQUEST_URI}!home/(.*)/$
RewriteRule ^home/(.*)$ [someurl.com...] [L,R=301]
RewriteRule ^home/(.*)/$ home_cache.php?country=$1

Help would be much appreciated....im presuming its a configuration thing.

jdMorgan

4:25 pm on Aug 15, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !home/(.*)/$
RewriteRule ^home/(.*)$ http://www.example.com/home/$1/ [L,R=301]

This rule will not work as expected, and is likely to loop because the second RewriteCond's pattern is incorrect. If I understand its purpose, it should read:

# If requested URL-path does not resolve to an existing file
RewriteCond %{REQUEST_FILENAME} !-f
# and does not already start with "/home"
RewriteCond %{REQUEST_URI} [b]!/ho[/b]me/(.*)/$
# then internally rewrite the request to the "/home" subdirectory
RewriteRule [b](.*) /home/$1 [L][/b]

Note that this modified code does an internal rewrite, so as to avoid 'exposing' your "/home" subdirectory to users and search engines. They do not need to know it is there, and this will make your search-indexed URLs shorter as well.

For your second rule:


RewriteRule ^home/(.*)/$ home_cache.php?country=$1

I see nothing that would prevent it from working, except the problem noted with the first rule.

I would recommend making the trailing slash optional, though:


RewriteRule ^home/(.*)[b]/?$[/b] home_cache.php?country=$1 [L]

Jim