Help in writing rewrite rulse for fancy urls

Discuss practical ways rearrange URLs using mod_rewrite.

Help in writing rewrite rulse for fancy urls

Postby hemanshurpatel » Mon Sep 22, 2008 4:54 am

Hello there
I need to write some more rewrite rules so that my urls looks fancy and it helps me in SEO perpose as well

my urls are how i want them to be

xxx.info/index.php5?title=Main_Page xxx.info
xxx.info/index.php5?title=abcd xxx.info/abcd
xxx.info/index.php5?title=Harry_patel xxx.info/Harry_patel
etc.

if the link contains ":" then that links should not be converted
i mean if
xxx.info/index.php5?title=abcd:efgh then this link should not be converted


using some google help what i have created is:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/*$ /index.php5?title=Main_Page [L,QSA]
RewriteRule ^([A-Za-z0-9-]+)/$ /index.php5?title=$1 [L,QSA]


but its not working, so please help me in creating the rules.
hemanshurpatel
 
Posts: 3
Joined: Mon Sep 22, 2008 4:14 am

Postby richardk » Tue Sep 23, 2008 11:56 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^$ /index.php5?title=Main_Page [QSA,L]

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([-a-z0-9]+)/?$ /index.php5?title=$1 [NC,QSA,L]


Mod_rewrite does not change the links/URLs outputted by your script.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby hemanshurpatel » Tue Sep 23, 2008 8:04 pm

Thanks rechardk

with your tips, my home page works :) , now my home page directs me to proper page
but none other page works

they direct me to 404 not found page :(

and yes i forget to mention that my urls contain underscore (_) as well.
can you please check it a bit.
hemanshurpatel
 
Posts: 3
Joined: Mon Sep 22, 2008 4:14 am

Postby richardk » Wed Sep 24, 2008 12:09 pm

/abcd gives you an Apache 404 error?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^$ /index.php5?title=Main_Page [QSA,L]

RewriteRule ^([-a-z0-9_]+)/?$ /index.php5?title=$1 [NC,QSA,L]


and yes i forget to mention that my urls contain underscore (_) as well.

Add it to the character class.
Code: Select all
[-a-z0-9_]

instead of
Code: Select all
[-a-z0-9]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby hemanshurpatel » Wed Sep 24, 2008 7:31 pm

hey thanks rechard geniuos
it works

it was my mistake , i haven't ad that ? before $ sign, and now it works completely

thank you once again
hemanshurpatel
 
Posts: 3
Joined: Mon Sep 22, 2008 4:14 am

Postby smithveg » Fri Dec 12, 2008 10:17 am

hemanshurpatel wrote:hey thanks rechard geniuos
it works

it was my mistake , i haven't ad that ? before $ sign, and now it works completely

thank you once again


Thank for this post. I solve my _ (underscore) problem
smithveg
 
Posts: 1
Joined: Fri Dec 12, 2008 9:35 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 17 guests

cron