Rewrite a URL via htaccess - .htaccess

I have a URL in the following structure like
http://www.naturaflowers.com/100-fresh-cut-wholesale-flowers.html
I want to rewrite the URL like
http://www.naturaflowers.com/fresh-cut-wholesale-flowers.html
We used "ultimate SEO url Plugin" to generate SEO friendly URL. The old URL structure is /index.php?main_page=index&cPath=category_id . My htaccess code is as follows :
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)-(.*).html$ index\.php?main_page=index&cPath=$1&%{QUERY_STRING} [L]
The above mentioned plugin and this htaccess code rewrite
index.php?main_page=index&cPath=100 to
/100-fresh-cut-wholesale-flowers.html . And now I want to
/100-fresh-cut-wholesale-flowers.html rewrite to
/fresh-cut-wholesale-flowers.html everywhere in my website through
htaccess .

Have your rules like this:
RewriteEngine On
RewriteBase /
RewriteRule ^[0-9]+-(.+?\.html)$ /$1 [L,R=302,NC]
RewriteRule ^(.+?)\.html$ index\.php?main_page=index&cPath=$1 [L,QSA,NC]

RewriteRule ^(/?)\d+-(.*)$ $1$2

Related

Clean URL htaccess - (?p=1)

How can I Rewrite with htaccess file the url
http://www.example.com/index.php?p=1
So it will look like this:
http://www.example.com/index.php
Try adding this :
RewriteEngine On
RewriteRule ^/?index.php$ http://www.example.com/? [L,R=301]

htaccess mod_rewrite and 301 redirect to friendly url

Now, I'm trying to write some htaccess code with mod_rewrite. I have problem with it :(
RewriteEngine On
RewriteRule ^home$ index.php?page=home
This is my code in .htaccess file. When I go to domena.com/index.php?page=home it's exactly same like domena.com/home
But, It's not friendly for google, 'cos we have double page:
domena.com/index.php?page=home
domena.com/home
It's same.
What I want to achieve? I want to user who choose domena.com/index.php?page=home redirect him to domena.com/home
Exactly, I want to on my website be exist ONLY friendly link.
Help me :(
You will need another rule to redirect old URL to new one.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteRule ^home/?$ index.php?page=home [L,NC,QSA]

Creating SEO friendly URLs with URL rewriting

I need to make SEO friendly URLs with URL rewriting from:
http://www.myurl.com/subfolder/index.php?service=example1&location=city1
http://www.myurl.com/subfolder/cars.php?service=example1&location=city1
http://www.myurl.com/subfolder/bicycle.php?service=example1&location=city1
to
http://www.myurl.com/subfolder/example1/example2/index.html
http://www.myurl.com/subfolder/example1/example2/cars.html
http://www.myurl.com/subfolder/example1/example2/bicycle.html
My URL rewriting doesn't work at all,
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^index/(\w+)/?$ index.php?service=$1&location=$2
RewriteRule ^cars/(\w+)/?$ cars.php?service=$1&location=$2
RewriteRule ^bicycles/(\w+)/?$ bicycles.php?service=$1&location=$2
And where should I put the .htaccess file? In the root or a subfolder?
This should probably work:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /subfolder/$3.php?service=$1&location=$2 [L]
You should put it in the root directory.

mod_rewrite from .php to .html for web crawlers

I am using mod_rewrite in .htaccess to redirect from .php to .html like this:
RewriteRule ^([^.]+).html$ /$1.php [QSA,L]
It works in a web browser, but Google is crawling the old URLs i.e. index.php and faq.php.
How I can redirect the index.php to index.html? My website URL is: http://www.21flats.com/.
Add [QSA,L,R=301] so Google will see that there has been a redirect. This adds a 301 redirect to the rewrite for search engines:
RewriteRule ^(.*)\.php$ /$1.html [QSA,R=301,L]
You have the redirect backwards, so change it and add the 301 rule and you are good.
You can try something like this:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]

.htaccess rewrite rule ,last query string is append to the url

Hi i make one cms sites and i need to rewrite my url
current my url is http://www.example.com/index.php?link=pages&cmsid=2&cmsLink=Carpet
it refers the cmsLink
I want my url like http://www.example.com/Carpet
I am using the following code
Options +FollowSymLinks
Options +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^index.php?link=(.*)&cmsid=(.*)&cmsLink=(.*) $3
To achive this url it not directly possible with .htaccess
I use regular expression and other tings in htacess as well
I put remove the cmsid
current my url is http://www.example.com/index.php?link=pages&cmsLink=Carpet
RewriteCond %{REQUEST_URI} !/admin
RewriteCond %{REQUEST_URI} !^/(.*).php
RewriteBase /
RewriteRule ^([^/]+)/?$ index.php?link=pages&cmsLink=$1&%{QUERY_STRING} [L]
it return me http://www.example.com/Carpet
Try changing your last rule to this:
RewriteRule ^(.+)$ /index.php?link=pages&cmsid=2&cmsLink=$1
Since you want to have url like http://www.example.com/Carpet, so cmsid and link in your url has to be hardcoded to 2 and pages.

Resources