Forum Moderators: phranque

Message Too Old, No Replies

.htaccess and conditions?

.htacces, variables

         

brnco

8:23 pm on Jun 19, 2007 (gmt 0)

10+ Year Member



Hi,
I am quite new to htaccess. I'm trying to change my URL's to COOL URL's for SEO. There are two pages det.php and det2.php I would like to change. The first piece of code works well but the second one has problems with content. The URL looks Ok but the content of the page is wrong. It takes content from the first piece of code

Please, could you help me with this?

RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^det2.php?menu=([^&]+)&cms=([0-9]+)&lan=([0-9]+)$
RewriteRule ^det2.php$ %1-%2-%3.html? [R=301]
RewriteRule ^([^/]+)-([0-9]+)-([0-9]+)\.html$ det2.php?rw=1&name=$1&cms=$2&lan=$3 [QSA]

RewriteCond %{QUERY_STRING} ^det.php?menu=([^&]+)&did=([0-9]+)&lan=([0-9]+)$
RewriteRule ^det.php$ %1-%2-%3.html? [R=301]
RewriteRule ^([A-Za-z][A-Za-z\ -]+)-([0-9]+)-([0-9]+)\.html$ det.php?rw=1&menu=$1&did=$2&lan=$3[QSA]

jdMorgan

4:49 am on Jun 20, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There are apparently lots of little problems with the code, so let's see if I'm a fair mind-reader and if this works any better:

# Redirect client request for dynamic "det2" URLs to static URL
RewriteCond %{QUERY_STRING} ^menu=([^&]+)&cms=([0-9]+)&lan=([0-9]+)$
RewriteRule ^det2\.php$ http://www.example.com/%1-%2-%3.html? [R=301,L]
#
# Internally rewrite static URL requests to dynamic URL, set "rw=1" to prevent redirect/rewrite looping
RewriteRule ^([^-]+)-([0-9]+)-([0-9]+)\.html$ det2.php?rw=1&name=$1&cms=$2&lan=$3 [QSA,L]
#
# Redirect client request for dynamic "det" URLs to static URL
RewriteCond %{QUERY_STRING} ^menu=([^&]+)&did=([0-9]+)&lan=([0-9]+)$
RewriteRule ^det\.php$ http://www.example.com/%1-%2-%3.html? [R=301,L]
#
# Internally rewrite static URL requests to dynamic URL, set "rw=1" to prevent redirect/rewrite looping
RewriteRule ^([a-z][a-z\ -]+)-([0-9]+)-([0-9]+)\.html$ det.php?rw=1&menu=$1&did=$2&lan=$3 [NC,QSA,L]

I should also note that there is another technique for avoiding the redirect/rewrite loop that the "rw=1" is apparently used to avoid here. But it would be better to fix what you have before embarking on any modifications.

%{QUERY_STRING} contains neither any part of the URL-path, nor the "?" that serves as the URL-path/query-string boundary indicator.

Note that the [NC] flag makes the pattern-match case-insensitive, so eliminates the need for [A-Za-z], and is faster.

Jim

brnco

6:49 am on Jun 20, 2007 (gmt 0)

10+ Year Member



thank you for your reply. but unfortunately still doesn't work.
the menu works ok (det.php) but (content page - det2.php) is probably still passing variables to det.php. <snip>

[edited by: jdMorgan at 1:24 am (utc) on June 21, 2007]
[edit reason] No URLS, please. See Terms of Service. [/edit]

brnco

8:56 pm on Jun 20, 2007 (gmt 0)

10+ Year Member



no ideas?

jdMorgan

1:18 am on Jun 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looking at this, the problem is that the URL output of the first rule will match the input pattern for the fourth rule. So, you will have to change the URL format so that this cannot happen. Since I don't know your site, I don't know what kind of change to suggest, except perhaps to map the det and det2 URLs into their own pseudo-directories, e.g. det/a-b-c.html and det2/d-e-f.html, to make them unique.

Jim