conflicting rewrites

Discuss practical ways rearrange URLs using mod_rewrite.

conflicting rewrites

Postby cl4im3r » Wed Jun 11, 2008 5:27 pm

Hi again Rich. Thnx for last fix.

I have one last problem, to do with conflicting rewrites. Sorry to bug you again, please.. answer in your own time, if your not bothered right now. :D

Here is the conflict:

Code: Select all
RewriteEngine On

RewriteRule ^(.*)\.htm $1.php
# Don't match existing files.
RewriteCond %{SCRIPT_FILENAME} !-f
# Don't match existing directories.
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /topic.php?titleurl_top=$1 [QSA,L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]


Titleurl_art and Titleurl_top share the same rewrite rule.

titleurl_art doesn't work.

I have tried..
Code: Select all
RewriteRule ^titleurl_art/([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]


As i heard this would seperate them, but it doesnt seem to work.

Any ideas Rich?

Thnx again, last few days have been hard, and you put things right, just like that. :D
cl4im3r
 
Posts: 15
Joined: Mon Jun 09, 2008 10:28 am

Postby richardk » Fri Jun 13, 2008 2:20 pm

As you have found out, the RewriteRules have to match different things.

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^(.+)\.htm /$1.php [QSA,L]

RewriteRule ^titleurl_art/([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ /topic.php?titleurl_top=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby cl4im3r » Fri Jun 13, 2008 3:54 pm

No luck i'm afraid.

It's really odd because when i delete this line,

Code: Select all
RewriteRule ^([^/\.]+)/?$ /topic.php?titleurl_top=$1 [QSA,L]


So the final code looks like this...

Code: Select all
RewriteEngine On

RewriteRule ^(.+)\.htm /$1.php [QSA,L]

RewriteRule ^titleurl_art/([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d


I get a 404 error.

It's the added "titleurl_art/" at the beginning that causes the 404 error.

Are there maybe any other alternatives methods to solving conflicting rewrites?
cl4im3r
 
Posts: 15
Joined: Mon Jun 09, 2008 10:28 am

Postby richardk » Fri Jun 13, 2008 4:28 pm

You get a 404 error when you go to /titleurl_art/something/?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby cl4im3r » Fri Jun 13, 2008 5:10 pm

Using this code...

Code: Select all
RewriteRule ^([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]


I get no error, works fine when trying to open, example: site.com/portal

But adding "titleurl_art/" at the beginning of the code like so:


Code: Select all
RewriteRule ^titleurl_art/([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]

gives me 404 error when trying to open, same example: site.com/portal
cl4im3r
 
Posts: 15
Joined: Mon Jun 09, 2008 10:28 am

Postby richardk » Sun Jun 15, 2008 10:48 am

But adding "titleurl_art/" at the beginning of the code like so:
Code: Select all
RewriteRule ^titleurl_art/([^/\.]+)/?$ /article.php?titleurl_art=$1 [QSA,L]

gives me 404 error when trying to open, same example: site.com/portal

You have to go to /titleurl_art/portal. You actually have to make the two URLs different.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby cl4im3r » Sun Jun 15, 2008 3:00 pm

aah, I understand now. thanks once again.

I have to ask? Is this the only technique available to stop conflicting rules?

I've looked at either of these two dynamic sites:

http://www.addictinggames.com/index.html

and

http://www.netfreestuff.co.uk/p_home.html

Both their categories, & their Articles appear as

site.com/categories
site.com/articles

with no conflicts, and without any need for an extra "/" forward slash.

If you do not know rich, I truly appreciate your help either way.

Thnx again.
cl4im3r
 
Posts: 15
Joined: Mon Jun 09, 2008 10:28 am

Postby richardk » Sun Jun 15, 2008 3:17 pm

With mod_rewrite it is. You could send the requests to one PHP file and write something to check if it's an article or a topic request.

For addictinggames.com, they might actually be using HTML files for categories and/or games. As there are a limited number of categories it would be easy to have files just for them. There doesn't even have to be much information in the file, it could just be "game=123" or "category=456" and a script could be run with that information.

For netfreestuff.co.uk, all category URLs start with /cat_ (then <number>_<number>_<text>.html), which is easily matched. All "freebie details" start with /fb (then <number>_<text>.html) which again can be matched.

without any need for an extra "/" forward slash.

As shown by netfreestuff.co.uk, you don't have to use a /, you just need to add something to make it unique.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby cl4im3r » Sun Jun 15, 2008 3:35 pm

Thanks alot rich, all makes sense to me now. :D
cl4im3r
 
Posts: 15
Joined: Mon Jun 09, 2008 10:28 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 23 guests

cron