mod_rewrite for redirecting url as cityname.domain.com

Discussions about Apache mod Rewrite, .htaccess, Use, experiences ... URL Rewriting.

Moderator: Moderators

mod_rewrite for redirecting url as cityname.domain.com

Postby rishibala143 » Sat Jan 29, 2011 6:28 am

Hi

I am new to mod_rewrite

I need two things to do in htacess

1. I want all my php pages to display as html

Example : index.php to index.html
aboutus.php to aboutus.html

I given like this

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^/]*)\.html$ index.php?action=$1
RewriteRule ^([^/]*)\.html$ aboutus.php?action=$1

This works good. But for this a query string is passes. I don’t want to give any query string. If I click index.php it should redirect to index.html. I don’t want to write separate for aboutus.php. within a single code it should redirect all php to html pages


2. The most wanted thing

I want to search a thing using city name in my project

For example

If I click the cityname eg.chennai

The following url will be like this : -http://www.domainname.com/search.php?city=chennai

But I want like this

-http://chennai.domainname.com

if I click Mumbai it should be -http://mumbai.domainname.com

How to do this ?

I want like this site

-http://www.clickindia.com/
-http://www.indialist.com

There if we click the city name it will redirect the url as cityname.domainname.com

Please help
rishibala143
 
Posts: 1
Joined: Sat Jan 29, 2011 6:25 am

Advertisement

Re: mod_rewrite for redirecting url as cityname.domain.com

Postby SeO » Sat Jan 29, 2011 11:19 am

rishibala143 wrote:1. I want all my php pages to display as html


Just to make things clear, mod_rewrite will not actually help in any way to rewrite url in your websites pages, it will only allow rewritten urls (eg url that do not match a physical file directly) to work (eg to hit a physical file on the server).

So it's up to you to rewrite the url in the pages.

rishibala143 wrote:Example : index.php to index.html
aboutus.php to aboutus.html

To do exactly this :
Code: Select all
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_-]+)\.html$ /$1.php [QSA,L,NC]


The QSA flag will make so page.html?var=val will hit page.php?var=val

In the code you posted, the second rewriterule is never used.

But, you could be willing not to actually use one php file per html url with something like :
Code: Select all
RewriteEngine On
RewriteBase /
RewriteRule ^([a-z0-9_-]+)\.html$ /index.php?page=$1 [QSA,L,NC]

In this scenario, page.html would hit index.php?page=page and it would be up to index.php to serve the proper content for all pages.

Note that in the above RewriteRules, if you replace [a-z0-9_-] with [a-z0-9_/-], you would be able to deal with directories :
/dir/page.html matching /dir/page.php (1st scenario) or index.php?page=dir/page (2nd one).

rishibala143 wrote:2. The most wanted thing


This requires more in depth settings in the server and DNS : subdomain rewrite problem - semi dynamic
SeO
Admin
Admin
 
Posts: 6334
Joined: Wed Mar 15, 2006 9:41 pm


Return to Apache mod Rewrite

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 2 guests