Explorer Explorer - 3 months ago 9
Apache Configuration Question

htaccess to write URL

I am trying to rewrite URL for users using htaccess file so that users can easily remember and make sure address bar stay cool.I accomplished to rewrite -

Rewrited URL



www.mysite.com/index.php?profile=2345

Actual URL wanted



www.mysite.com/profile/2345

.htaccess



RewriteRule ^profile/([0-9]+)/?$ index.php?profile=$1 [NC,L]


Unable to



**1. Multiple **

www.mysite.com/profile=2345&a=65&b=34&c=7&d=54

into

www.mysite.com/profile/2345/a/65/b/34/c/7/d/54

2. Is it possible to go further like?

profile.mysite.com/2345/a/65/b/34/c/7/d/54

Answer

1.

RewriteRule ^profile/([0-9]+)/a/([0-9]+)/b/([0-9]+)/c/([0-9]+)/d/([0-9]+)/?$ index.php?profile=$1&a=$2&b=$3&c=$4&d=$5 [NC,L] 

2.

RewriteCond %{HTTP_HOST} ^profile\.mysite\.com$
RewriteRule ^([0-9]+)/a/([0-9]+)/b/([0-9]+)/c/([0-9]+)/d/([0-9]+)/?$ index.php?profile=$1&a=$2&b=$3&c=$4&d=$5 [NC,L]

3.

RewriteCond %{HTTP_HOST} ^([a-z]+)\.mysite\.com$
RewriteRule ^([0-9]+)/([abcd])/([0-9]+)/([abcd])/([0-9]+)/([abcd])/([0-9]+)/([abcd])/([0-9]+)/?$ index.php?%1=$1&$2=$3&$4=$5&$6=$7&$8=$9 [NC,L]

RewriteCond %{HTTP_HOST} ^([a-z]+)\.mysite\.com$
RewriteRule ^([0-9]+)/([abcd])/([0-9]+)/([abcd])/([0-9]+)/([abcd])/([0-9]+)/?$ index.php?%1=$1&$2=$3&$4=$5&$6=$7 [NC,L]

RewriteCond %{HTTP_HOST} ^([a-z]+)\.mysite\.com$
RewriteRule ^([0-9]+)/([abcd])/([0-9]+)/([abcd])/([0-9]+)/?$ index.php?%1=$1&$2=$3&$4=$5 [NC,L]

RewriteCond %{HTTP_HOST} ^([a-z]+)\.mysite\.com$
RewriteRule ^([0-9]+)/([abcd])/([0-9]+)/?$ index.php?%1=$1&$2=$3 [NC,L]

RewriteCond %{HTTP_HOST} ^([a-z]+)\.mysite\.com$
RewriteRule ^([0-9]+)/?$ index.php?%1=$1 [NC,L]