Need Help with a simple mod_rewrite code

New to mod_rewrite? This is a good place to start.

Need Help with a simple mod_rewrite code

Postby P30TiP » Fri Sep 11, 2009 7:11 am

Hello,

I have a site with pages like example.com/xxx.php and I want urls to be changed to directories like:

example.com/one.php become /numbers/one

If you can give me an example of this code, I can copy it and change it for the others too.

these are the things i want to change (if you wanna know all):

e.g. : home.php ---> example.com/home

home.php --> /home
shared.php --> /shared/plans
features.php --> /shared/features
domain.php --> /domain
news.php --> /news
bank.php -->/bank

as I said if you give me an example of doing this with just 1 of my urls, then i can figure out the rest i think.
P30TiP
 
Posts: 8
Joined: Thu Jan 01, 2009 9:44 pm

Postby richardk » Sat Sep 12, 2009 2:58 pm

Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /home to /home.php
# /domain to /domain.php
# /news to /news.php
# /bank to /bank.php
RewriteRule ^(home|domain|news|bank)$ /$1.php [QSA,L]

# /shared/plans to /shared.php
RewriteRule ^shared/plans$ /shared.php [QSA,L]

# /shared/features to /features.php
RewriteRule ^shared/features$ /features.php [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby P30TiP » Sat Sep 12, 2009 11:34 pm

sorry i didn't say like /home to home.php, i said the opposite (home.php to /home)
P30TiP
 
Posts: 8
Joined: Thu Jan 01, 2009 9:44 pm

Postby richardk » Sun Sep 13, 2009 11:59 am

Exactly what should happen?

When the user visits /home.php should it show /home?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /home.php to /home
# /domain.php to /domain
# /news.php to /news
# /bank.php to /bank
RewriteRule ^(home|domain|news|bank)\.php$ /$1 [QSA,L]

# /shared.php to /shared/plans
RewriteRule ^shared\.php$ /shared/plans [QSA,L]

# /features.php to /shared/features
RewriteRule ^features\.php$ /shared/features [QSA,L]


Or when the user visits /home.php should the address bar change to show /home?
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# /home.php to /home
# /domain.php to /domain
# /news.php to /news
# /bank.php to /bank
RewriteRule ^(home|domain|news|bank)\.php$ /$1 [R=301,L]

# /shared.php to /shared/plans
RewriteRule ^shared\.php$ /shared/plans [R=301,L]

# /features.php to /shared/features
RewriteRule ^features\.php$ /shared/features [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 25 guests

cron