User Friendly URL for CMS

Discuss practical ways rearrange URLs using mod_rewrite.

User Friendly URL for CMS

Postby ehappylucky05 » Tue Aug 19, 2008 8:12 am

Hi,
I have been looking at this forum trying to find a solution for what I am trying to implement, but with no luck.

Here is what I am trying to do, I am trying to convert this url

http://www.whatever.com/cms/scripts/scriptnumber123/abc

Please note that "scripts/scriptnumber123" is not an existing script. It is a node number where my script resides.



http://www.whatever.com/cms/mycontent/abc

where abc is the parameter value that I parse into the script to render the content.

I tried the following mod_rewrite, but it's not working, hope someone can help me out.

RewriteRule ^/cms/mycontent/([^\.]+)$ /cms/scripts/scriptnumber123/$1 [L]

Thanks a lot in advance!!!
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Update

Postby ehappylucky05 » Wed Aug 20, 2008 10:53 am

Hi,
I was able to get the mod_rewrite to work, but, here comes other new problems:

Here is what I got for my rewrite rules that works
################################

RewriteRule ^mycontent1/(.*)$ index.php?q=node/123/$1 [QSA]
RewriteRule ^mycontent2/(.*)$ index.php?q=node/456/$1 [QSA]
################################

However, when I tried to use the rule below for my all other url aliases, the whole site gone wrong, seems like the server is not able to recognize the right path
#################################
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

My question is, how can I enabled these 3 rules at the same time without
messing up each other. I know the first 2 rules above can stay together, and I can keep adding some new rules with specific node number, but the last rule is also important for my applications, because I might have another thousands general aliases that will use the last rule.

Hope someone can help!
Thanks a thousands times!
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Wed Aug 20, 2008 11:36 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^mycontent1(/(.*))?$ /index.php?q=node/123/$2 [QSA,L]
RewriteRule ^mycontent2(/(.*))?$ /index.php?q=node/456/$2 [QSA,L]

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

Postby ehappylucky05 » Wed Aug 20, 2008 11:46 am

richardk wrote:Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^mycontent1(/(.*))?$ /index.php?q=node/123/$2 [QSA,L]
RewriteRule ^mycontent2(/(.*))?$ /index.php?q=node/456/$2 [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?q=$1 [QSA,L]


Hi Richard,
Thanks for your reply, I tried it, but the server showed the following error
################
Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
################
ehappylucky05
 
Posts: 14
Joined: Tue Aug 19, 2008 8:02 am

Postby richardk » Wed Aug 20, 2008 11:54 am

Edit: Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^mycontent1(/(.*))?$ ./index.php?q=node/123/$2 [QSA,L]
RewriteRule ^mycontent2(/(.*))?$ ./index.php?q=node/456/$2 [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?q=$1 [QSA,L]
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 3 guests

cron