Problem with modrewrite

Discuss practical ways rearrange URLs using mod_rewrite.

Problem with modrewrite

Postby Pablo90 » Thu Oct 09, 2008 7:54 am

Hi guys I'm a newbie and I'm Italian, so my English is not so fine..

I've this problem whit my htaccess:
Code: Select all
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?act=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?act=articolo&id=$1 [L]


The second one is an article..

I would like that if I go in a section, it doesn't have to read the code as an article.

Now it is:
www.domain.com/?act=contact-->www.domain.com/contact --> Ok, it works fine
But I can't do www.domain.com/my-news-title because it read it as an act instead of an ID

I would like to say "use this condition or that one"..How can I do?

Thanks in advance, Paolo
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Re: Problem with modrewrite

Postby Pablo90 » Thu Oct 09, 2008 9:18 am

Sorry I forgot another "problem":
Now the directories that really exist and are on my server "don't work"..I mean, I've ma "forum" directory, and if a go to mydomain.com/forum/ doesn't work, because of my htaccess it read "forum" as "?act=forum" that doesn't exist..So I've to write "forum/index.php"..

Can I split "really directories" and "rewrited directories" ?
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Thu Oct 09, 2008 11:45 am

The second one is an article..

I would like that if I go in a section, it doesn't have to read the code as an article.

Now it is:
www.domain.com/?act=contact-->www.domain.com/contact --> Ok, it works fine
But I can't do www.domain.com/my-news-title because it read it as an act instead of an ID

I would like to say "use this condition or that one"..How can I do?

You have to add something to the URLs to make them unique, for example /articolo/article-title.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# Ignore existing files.
RewriteCond %{SCRIPT_FILENAME} !-f
# Ignore existing directories.
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)/?$          /index.php?act=$1             [QSA,L]

RewriteRule ^articolo/([a-zA-Z0-9-]+)/?$ /index.php?act=articolo&id=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Pablo90 » Fri Oct 10, 2008 1:23 am

thanks, but I knew that..I hoped that there was something which doesn't need a "directory" before the title..

Thanks anyways.

Sorry but:
Code: Select all
# Ignore existing files.
RewriteCond %{SCRIPT_FILENAME} !-f
# Ignore existing directories.
RewriteCond %{SCRIPT_FILENAME} !-d


Is it what I wanted? To split "real directories" and "rewrited directories"?
What the first rule serves for? The files work fine, just the directories doesn't..Should I insert that code anyways?
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Fri Oct 10, 2008 12:38 pm

What the first rule serves for? The files work fine, just the directories doesn't..Should I insert that code anyways?

The first condition is just in case you had a file that matched the rule. You can remove it if you want to.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Pablo90 » Sat Oct 11, 2008 2:19 am

richardk wrote:
What the first rule serves for? The files work fine, just the directories doesn't..Should I insert that code anyways?

The first condition is just in case you had a file that matched the rule. You can remove it if you want to.

Ah ok thanks..So the priority go to the existing files, doesn't it?

I've another question :D
If I insert in my url something that doesn't exist as action, for example:
domain.tld/cazzata and there isn't ?act=cazzata appears a blank page, white..
Can I set that if the action doesn't exist, so give error 404 (not found)?
Pablo90
 
Posts: 18
Joined: Thu Oct 09, 2008 7:45 am

Postby richardk » Sat Oct 11, 2008 9:07 am

Ah ok thanks..So the priority go to the existing files, doesn't it?

If you have the !-f condition, and go to a file that exists that matches the rule, the file will still show (the rule will not match).

If I insert in my url something that doesn't exist as action, for example:
domain.tld/cazzata and there isn't ?act=cazzata appears a blank page, white..
Can I set that if the action doesn't exist, so give error 404 (not found)?

You have to do that with PHP. Mod_rewrite doesn't know if your script will find an page or not.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 13 guests

cron