GET request htaccess redirection - regex

I need to redirect url from
website.com/search.php?city=india&keyword=laptop
to
website.com/search/india/laptop
How can i do this with htaccess
Present code in my htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ search.php?city=$1&keyword=$2

You can use this rule in your root .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+search\.php\?city=([^&]+)&keyword=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=301,L,NE]
RewriteRule ^search/([\w-]+)/([\w-]+)/?$ /search.php?city=$1&keyword=$2 [L,QSA]

Related

Htaccess Removing .php extension to .html make an URL Not found

To remove .php extension from URL and replaced with .html
i have wrote:
Options -Indexes
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php $1.html [QSA,L]
This work fine and i the extension changed, but i get this message:
Not Found
The requested URL /**xxxxxx**.html was not found on this server.
To serve .php files as .html you can use this code:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1.html [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]
wrong way round? try
RewriteRule ^(.*)\.html $1.php [QSA,L]

Htaccess rewrite url not working

I have created a .htaccess file to rewrite url. But when i opened the url which should be rewrited by the htaccess the url was not changed. Here is my .htaccess
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteRule seller/username/(.*)/ seller.php?username=$1
RewriteRule seller/username/(.*) seller.php?username=$1
Please help me out as i am beginner to htaccess. Thanks in advance
Have it this way:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+seller/\.php\?username=([^\s&]+) [NC]
RewriteRule ^ /seller/username/%1? [R=302,L]
RewriteRule ^seller/username/(.+)/?$ seller.php?username=$1 [L,QSA]

Rewrite rule to an other domain keeping rest of url

This is what I need to do:
website EXAMPLE with url
/?VVWM=$59095-K9T-50U00-VX0U**|jDDQvcZbTESbGqI2AJ8Iww|dIWecCGiGUive6I2AJ8Iww||||1|0$&utm_source=followup-offerte&utm_medium=email&utm_campaign=VVWM
has to redirect to:
http://www.sluitsnel.nl/goedkope-scooterverzekering/?VVWM=$59095-K9T-50U00-VX0U**|jDDQvcZbTESbGqI2AJ8Iww|dIWecCGiGUive6I2AJ8Iww||||1|0$&utm_source=followup-offerte&utm_medium=email&utm_campaign=VVWM
So the indication for this redirection is:
http://www.goedkope-scooterverzekeringen.nl/?VVWM=$59095-K9T-50U00-VX0U
Thanks in advcance!
Greetings,
Ivar
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?goedkope-scooterverzekeringen\.nl$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?(VVWM=$59095-K9T-50U00-VX0U[^\s]*) [NC]
RewriteRule ^ http://www.sluitsnel.nl/goedkope-scooterverzekering/?%1 [R=301,L,NE]

htaccess redirect file request of one to another file

I need modificate file request http://subdomain.site.com/file.txt -> http://site.com/file-subdomain.txt
Please help with htaccess code. Thanks!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(subdomain)\.(site\.com)$ [NC]
RewriteRule ^file\.txt$ http://%2/file-%1.txt [L,R=301,NC]
EDIT:
RewriteCond %{HTTP_HOST} ^(subdomain)\.(site\.com)$ [NC]
RewriteRule ^file\.txt$ /file-%1.txt [L,NC]

why the .htaccess file can't rewrite the dynamic url in my website

the current is:
http://www.vitalimaging.com/about.php?page=overview_vision
want to clean the url, and here is my code:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^about/([A-Za-z0-9-]+)/?$ about.php?page=$1 [L]
why it's not working?
Your example also has underscore in query string but your regex in RewriteRule doesn't include _. Simplify your regex like this:
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(about)\.php\?page=([^&\s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]
RewriteRule ^about/([^/]+)/?$ /about.php?page=$1 [L,QSA,NC]