Changing a long url to short - .htaccess

How can I change
www.example.com/index.php?page=2_4_home
to
www.example.com/2/4/home
or
www.example.com/2/4/home/
with htaccess? Thanks

Try
RewriteEngine on
RewriteRule ^([0-9]+)/([0-9]+)/([a-zA-Z]+)/?$ /index.php?page=$1_$2_$3 [L]

Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+(?:index\.php|)\?page=([0-9]+)_([0-9]+)_([^&\ ]+)
RewriteRule ^ /%1/%2/%3/? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/([0-9]+)/([^/]+)/? /index.php?page=$1_$2_$3 [L,QSA]

Related

Simple .htaccess rewrite for single get parameter

How can I rewrite
http://data.example.com/?file=test
to
http://data.example.com/test
via .htaccess?
Try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /\?file=([^\ &]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /?file=$1 [L,QSA]

Changing URL .htaccess

From this:
http://ice-phoenix.dx.am/jlpt/form/try_question.php
To This:
http://ice-phoenix.dx.am/jlpt/try_question
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^jlpt/form/try_question\.php$ jlpt/try_question/ [L]
Can any help me?
Thank you so much.
Try this in Root/.htaccess file
RewriteEngine On
RewriteCond %{THE_REQUEST} /jlpt/form/([^.]+)\.php [NC]
RewriteRule ^ /jlpt/%1? [R,L]
RewriteRule ^jlpt/([^/]+)/?$ /jlpt/form/$1.php [L,NC]

redirect m.php to m.domain.com htaccess

Is it possible to redirect
http://www.url.com/m.php?name=Bill
to
http://m.url.com/Bill/
via htaccess?
I have seen some examples but I'm not sure what
they use to accomplish that
How about:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?url\.com$ [NC]
RewriteCond %{THE_REQUEST} \ /+m\.php\?name=([^&\ ]+)
RewriteRule ^ http://m.url.com/%1/? [L,R]
RewriteCond %{HTTP_HOST} ^m\.url\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /m.php?name=$1 [L,QSA]
assuming that both m.url.com and www.url.com point to the same document root.

SEF urls htaccess

Currently my url structure is like:
http://mysite/index.php?page=main
http://mysite/index.php?page=bowling
http://mysite/index.php?page=inn
How to optimize this structure by leaving just (main,bowling,inn respectively) ?
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^&]+)&id=([0-9]+)
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{THE_REQUEST} \ /+index\.php\?page=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([0-9]+)/?$ /index.php?page=$1&id=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L]
make sure mod_rewrite is turned on.

language redirect from GET parameter htaccess

I have this code, it redirecs www.example.com?index.php?q=home&lang=en into www.example.com/home. I would like to redirect it into www.example.com/en/home. Is it possible?
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php?q=$1&lang=$2 [L,QSA]
RewriteRule ^([^/]*)(.*)$ $1[L,QSA]
Thanks in advance
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z]{2})/(.*)$ /index.php?q=$2&lang=$1 [L,QSA]

Resources