apache rewrite two php variables and remove php extension - php

I have this url:
http://www.website.co.uk/search.php?search=test&cat=catname
What I would like is:
http://www.website.co.uk/search/test/catname
I have tried this for the variables:
Options +FollowSymLinks
RewriteRule ^page/([^/]+)/?$ search.php?search=$1
and this to hide the php extension:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php[\s?] [NC]
RewriteRule ^ %1 [R=301,L]
and it doesnt seem to do anything

You can use this in root .htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+search\.php\?search=([^\s&]+)&cat=([^\s&]+) [NC]
RewriteRule ^ /search/%1/%2? [R=302,L]
RewriteRule ^search/([^/.]+)/([^/.]+)/?$ /search.php?search=$1&cat=$2 [L,QSA,NC]
RewriteRule ^page/([^/]+)/?$ /search.php?search=$1 [L,QSA,NC]

Related

mod rewrite single url .php

How can I rewrite a single URL with the code below?
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
You can change your regex pattern to make it target only home.php:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(home)\.php[?/\s] [NC]
RewriteRule ^ %1 [R=301,L]
RewriteRule ^(home)/?$ $1.php [L]

Vanity URL not working

I am using htaccess to try and rewrite a url. I have tried about 10 versions of the code and examples but nothing makes any change. I know mod_rewrite is working because it is adding www to the url, but the vanity URL won't work.
RewriteRule ^franchise/([0-9]+)/?$ franchise-information.php?franchiseid=$1 [NC,L] # Handle product requests
Here is the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^franchise/([0-9]*?)/$ franchise-information.php?franchiseid=$1 [NC,L]
</IfModule>
And here is the URL:
http://www.playballkids.com/franchise-information.php?franchiseid=162
You can use this code in your DOCUMENT_ROOT/.htaccess file:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /franchise-information\.php\?franchiseid=([^\s&]+) [NC]
RewriteRule ^ franchise/%1? [R=302,L,NE]
RewriteRule ^franchise/(\d+)/?$ franchise-information.php?franchiseid=$1 [NC,L,QSA]

redirect "non-www" domain to "www"domain with .htaccess rewrite

I couldn't find the solution for "non-www" to "www" domain redirection. I have tried the following :
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com [NC]
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]
# Remove index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
</IfModule>
So, how can I redirect, for example domain.com or www.domain.com to http://www.domain.com ?.
Something like should work :
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Here is what should help you:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Can you try this ?
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Seems apache mod_rewrite module is not enabled. So Make sure the Apache module mod_rewrite is enabled on your web server.
Try again this and see..It must work.
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
See here - http://iyngaran.info, It is working. So no problem with the rule
How To Create Temporary and Permanent Redirects with Apache click hear
To automatically add a www to your domain name:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
or
.htaccess To Redirect URLs
To use htaccess to redirect URL just copy and paste the snippet below and replace example.com with your domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
More info true ans
Redirecting non-www to www with .htaccess

Need to rewrite URL in .htaccess?

i need to rewrite the urls as below from your help.
i have this url for search
search-job.php?category=Accountancy&emp_type=Long+Term&working_pattern=Full+Time&location=Algeria&search=Search+Job
to
search-job-in-Accountancy-for-Full+Time-in-Algeria.html
OR from this
search-job.php?category=2&emp_type=2&working_pattern=2&location=12&search=Search+Job
To this
search-job-2-2-2-12.html
i have already done this
job-detail.php?j=Exalture-Software-Labs-Pvt-Ltd-Application-Developer-Websphere-Commerce-Suite-ais-GBS-in-India-Full-Time-Mumbai-11.html
To This
job-detail/Exalture-Software-Labs-Pvt-Ltd-Application-Developer-Websphere-Commerce-Suite-ais-GBS-in-India-Full-Time-Mumbai-11.html
My .htaccess is below
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /temp
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+job-detail\.php\?j=([^\s&]+) [NC]
RewriteRule ^ job-detail/%1? [R=301,L]
RewriteRule ^job-detail/([^/]+)/?$ job-detail.php?j=$1 [L,QSA]
Pls provide some help.
You need these additional rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search-job\.php\?category=([^&]*)&emp_type=([^&]*)&working_pattern=([^&]*)&location=([^&]*)&search=([^\s&]+) [NC]
RewriteRule ^ search-job-%1-%2-%3-%4? [R=301,L,NE]
RewriteRule ^search-job-([^-]*)-([^-]*)-([^-]*)-([^-]*) search-job.php?category=$1&emp_type=$2&working_pattern=$3&location=$4&search=Search+Job [L,QSA]

Simple htaccess redirection

I would like to create a redirection like this:
http://www.myserver.com/recipe/xxxxx.html?v1=blabla&fb_action_ids=bla&v3=blablabla
To
http://www.myserver.com/recipe/xxxx.html
Note: xxxx in the url is different according to the page.
htaccess:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^home.htm http://www.xxxxxxxxxx.co.uk/ [R=301,NC,L]
RewriteRule ^breads.htm http://www.xxxxxxxxxx.co.uk/whatwemake/ [R=301,NC,L]
RewriteRule ^cakes.htm http://www.xxxxxxxxxx.co.uk/patisserie/ [R=301,NC,L]
RewriteRule ^farmers_market.htm http://www.xxxxxxxxxx.co.uk/wheretobuy/ [R=301,NC,L]
RewriteRule ^about_us.htm http://www.xxxxxxxxxx.co.uk/ourstory/ [R=301,NC,L]
RewriteRule ^contacts.htm http://www.xxxxxxxxxx.co.uk/contact/ [R=301,NC,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(recipe/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(news/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(event/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
SetEnv APPLICATION_ENV production
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/+((?:news|event|recipe)/[^.]+\.html)\?fb_action_ids=[^\s]+ [NC]
RewriteRule ^ /%1? [R=302,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
This thing is via GET method [?v1=blabla&v2=bla&v3=blablabla] use POST then
You need a simple rewrite rule
RewriteRule ^(.*).html(.*) $1.html

Categories