Using mod-Rewrite with 5 pages (substitution submenu)

For example, I got 5 pages ( index.php

, about.php

, portfolio.php

, gallery.php

, contact.php

).

Let's say id 1

.

Original url:

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 this possible with mod-rewrite? And if I'm on a page index.php

, what <a href="" >

goes on about.php

, if text modification is possible?

Thanks a lot: D I appreciate your help: D

EDIT

One more thing: subdomain folder My wildcard public_html/folder/

Anubhava solution

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 place the .htaccess file in the directory where the pages are located.

+3


source to share


2 answers


Enable mod_rewrite and .htaccess via httpd.conf

and then place this code .htaccess

in your directory DOCUMENT_ROOT

:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# EDIT: to make http://1.domain.com/ load /about
RewriteCond %{HTTP_HOST} ^1\.(domain\.com$ [NC]
RewriteRule ^$ /about [L]

RewriteCond %{HTTP_HOST} ^1\.(domain\.com$ [NC]
RewriteRule ^(index|about|portfolio|gallery|contact)/?$ http://www.%1/folder/$1.php?id=1 [R=302,L,NC,QSA]

      



Once this has been created, 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>

+1


source


You need to modify your .htaccess file. write the below code to hide the file extension.

   Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^([a-zA-Z])\$ $1.php [NC]

      



And after that you give the url in the anchor link like / index etc.

Greetings.

0


source







All Articles