Forum Moderators: phranque
here is my code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^foo/$ /foo.php [L]
RewriteRule ^foo/([A-Za-z]*) /foo.php?name=$1 [L]
I am getting 404 document not found whenever I try to visit http://example.com/project/foo/New-Application
so what am I doing wrong. please help.
RewriteConds apply only to the *single* RewriteRule that follows them.
Use the [NC] flag to make pattern matches case-insensitive, rather than using [A-Za-z].
Using "+" instead of "*" in the second rule will make the code work with the rules in either order.
I'd suggest:
RewriteEngine on
RewriteRule ^foo/$ /foo.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^foo/([A-Z\-]+)$ /foo.php?name=$1 [NC,L]
For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].
Jim
But if "lyrics" in the URL means that you *always* call artist.php, then you could use URLs like
http://www.example.com/lyrics/J-LO/Get-right/
and use a rule like this example:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^lyrics/([A-Z\-]+)/([A-Z\-]+)/?$ /artist.php?artist=$1&title=$2 [NC,L]
Think about how the virtual directories in requested URLs are associated with real files or with scripts. This will help you write rules to map URLs to files and scripts.
Jim
my site is portal which has two sections. lyrics section and music section.
in my lyrics section I have three main files which are lyrics/artist.php, lyrics/song.php and lyrics/atoza.php and same applies to music section.
my current urls look like this
http://www.example.com/lyrics/artist.php?artistname=J-LO
http://www.example.com/lyrics/song.php?artist=J-LO&song=Get-right
http://www.example.com/lyrics/atoza.php?letter=j
so what I would like to have is
http://www.example.com/lyrics/J-LO/
http://www.example.com/lyrics/J-LO/Get-right/
http://www.example.com/lyrics/j/
I have attempted your example in the library but with no luck.
Have a look at the tutorials in the library to get an understanding of what you need to do and you should have a good idea of where you are going wrong.
Check the 'Beginngers' and 'Changing Dynamic URLs to Static' entries.
(I think they have the exact explanation you need.)
Apache Tutorials and Library [webmasterworld.com]
Justin