Let's say I got 5 pages (index.php
, about.php
, portfolio.php
, gallery.php
, contact.php
).
Let's say the id is 1
.
The original url is :
www.domain.com/folder/index.php?id=1
,
www.domain.com/folder/about.php?id=1
and so on...
Now, I want to change it to :
1.domain.com/index
,
1.domain.com/about
,
1.domain.com/portfolio
,
1.domain.com/gallery
,
1.domain.com/contact
Is it possible with mod-rewrite ? And if I'm in the index.php
page, whats the <a href="" >
that goes to about.php
if the mod-rewrite is possible?
Thank you very much :D I appreciate your help :D
EDIT
One more thing, My wildcard subdomain folder is public_html/folder/
The Solution By Anubhava
Edited with subdomain codes :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# EDIT BY ANUBHAVA: to make http://1.domain.com/ load /about as default page
# Replace /about with any other page you want as default page
RewriteCond %{HTTP_HOST} ^1\.(domain\.com$ [NC]
RewriteRule ^$ /about [L]
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteRule ^(index|about|portfolio|gallery|contact)/?$ /$1.php?id=%2 [L,NC,QSA]
Make sure your wildcard subdomain directory is where the pages are. Also put your .htaccess file in the directory where the pages are.
Enable mod_rewrite and .htaccess through
httpd.conf
and then put this code in your.htaccess
underDOCUMENT_ROOT
directory:Once that is in place create href links like this:
<a href="http://1.domain.com/about">About Us</a>
or<a href="http://1.domain.com/contact">Contact Us</a>
You need to change in the .htaccess file. write the below code in that it will hide the extension of the file.
And after that you will give the URL in anchor link like /index and so on.
Cheers.