Should be simple

Discuss practical ways rearrange URLs using mod_rewrite.

Should be simple

Postby mpman » Wed Oct 01, 2008 6:37 am

Hi,
How do i re-write my intial URL (index.php) to include a variable -->
'index.php?id=home'

This should happen on the initial page load...

Since its the index page it is hidden at first but it should still be able to carry a variable.


Thanks 8)
mpman
 
Posts: 3
Joined: Wed Oct 01, 2008 6:34 am

Postby richardk » Wed Oct 01, 2008 11:18 am

Do you want to see that the id=home is added?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

# If the query string is empty.
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(index\.php)?$ /index.php?id=home [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mpman » Thu Oct 02, 2008 5:59 am

Thanks!!

It partially worked:
I had to use the entire URL because i used a folder and not the site ROOT.

RewriteRule ^(http://www.site.com/myproject/index\.php)?$ http://www.site.com/myproject/index.php?id=home

Is that valid?
mpman
 
Posts: 3
Joined: Wed Oct 01, 2008 6:34 am

Postby richardk » Thu Oct 02, 2008 7:26 am

The RewriteRule matches the part of the URL after the current directory (that the .htaccess file is in) up to the query string.

If the .htaccess file is in /myproject you want
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(index\.php)?$ /myproject/index.php?id=home [R=301,L]


If your .htaccess file is in your document root you want
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^myproject/(index\.php)?$ /myproject/index.php?id=home [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby mpman » Thu Oct 02, 2008 9:46 am

Got it, thanks Richard :D
mpman
 
Posts: 3
Joined: Wed Oct 01, 2008 6:34 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 10 guests

cron