I have a bit of hard time trying to understand what is wrong with the 3rd line of this rewrite rule :
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
RewriteRule ^fr/lecon-de-kite\.html$ kite-lessons.php?lang=fr [L]
RewriteRule ^fr$ index.php?lang=fr [L]
RewriteRule ^it$ index.php?lang=it [L]
when I try to reach http://localhost/kitemeup/fr/lecon-de-kite.html I get an Not Found error
Have it like this in your site root .htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^fr/lecon-de-kite\.html$ kite-lessons.php?lang=fr [L]
RewriteRule ^(it|fr)/?$ index.php?lang=$1 [L,QSA]
RewriteRule ^(.+)\.html$ $1.php [L,NC]
Just understand that ordering of rules is important as mod_rewrite processes them from top to bottom. Your html -> php rule was taking precedence and converting all .html URIs to .php making your 2nd rule ineffective.
Related
This is my .htaccess file i just want to rewrite the page from one url to another.But it moved 404 page
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^([^/]+)/article/([^/]+)$ /index.php?option=com_vendorsearch&view=article&title=$2 [L]
RewriteRule ^([^/]+)/polls/([^/]+)$ /index.php?option=com_vendorsearch&view=polls&id=$2 [L]
RewriteRule ^([^/]+)/coupons/([^/]+)$ /index.php?option=com_vendorsearch&view=coupons&id=$2 [L]
RewriteRule ^([^/]+)/images/([^/]+)$ /index.php?option=com_vendorsearch&view=images&id=$2 [L]
RewriteRule ^([^/]+)/videos/([^/]+)$ /index.php?option=com_vendorsearch&view=videos&id=$2 [L]
Probably you need your first rules as:
RewriteRule ^[^/]+/articles/([^/]+)/?$ /index.php?option=com_vendorsearch&view=article&title=$1 [L,QSA,NC]
I added the following Rewrite rule to .htaccess:
RewriteEngine on
RewriteRule ^page/?$ index.php?cat=123 [L]
and it loads content of /index.php?cat=123 when I go to www.site.com/page
The problem is that I also need to set up redirection from www.site.com/index.php?cat=123 to www.site.com/page
but when I try to do this I get "too many redirections" error. Any idead how fix this?
RewriteEngine on
RewriteRule ^page/?$ index.php?cat=123 [L]
RewriteCond %{QUERY_STRING} ^cat=123$
RewriteRule ^index\.php$ http://www.mysite.com/page [L,R=301]
I would like to change urls from:
http://subdomain.domain.com/page/ to http://subdomain.domain.com/?page=pagename
and also:
http://domain.com/page/ to http://domain.com/?page=pagename
though haven't had much success.
Here is my htaccess file so far [updated]
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Remove 'www'
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# Add slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://resolutiongaming.com/$1/ [L,R=301]
# Subdomain redirect
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
I used RewriteRule ^([a-zA-Z]+)/$ ?page=$1 which seemed to work for the domain url but not the subdomain. Any help would be appreciated.
Actually had to do something like this recently. Try this for your Subdomain redirect block:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$2 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$2 [R=301,L]
Or maybe this; note the change from $2 to $1:
RewriteRule ^/(webdev)/(.*)$ http://webdev.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(artwork)/(.*)$ http://artwork.resolutiongaming.com/$1 [R=301,L]
RewriteRule ^/(music)/(.*)$ http://music.resolutiongaming.com/$1 [R=301,L]
EDIT: Or Maybe try this. Note that you need to capture two parts of the URL to rewrite as you are explaining. Each item in parenthesis ( and ) corresponds to a string in the rewrite. Try this. Using your nicer regular expression RewriteRule as you mention in the comments:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/$2 [R=301,L]
Or maybe this:
RewriteRule ^([a-zA-Z]+)/(.*)$ /$1/page=$2 [R=301,L]
So it was an easy fix really. I basically put a .htaccess file in each subdomain directory that looks like this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
# Search engine optimization
RewriteRule ([a-zA-Z]+)/$ ?page=$1
Hope this helps someone. :D
I wanted to have http://www.mywebsite.com/cd2012/legal rather than http://www.mywebsite.com/cd2012/index.php?legal=1
i have tried
Options +FollowSymLinks
RewriteEngine on
RewriteRule guarantees/(.*) cd2012/index\.php/legal=$1 [R=301,L]
RewriteRule guarantees cd2012/index\.php/legal=$1 [R=301,L]
RewriteRule ^guarantees/$ cd2012/index\.php/legal=$1 [R=301,L]
none of them working.
If you want to rewrite, you don't want to use [R=301,L] as this basically means "tell the users browser that this document is permanently moved to this location"
You also shouldn't escape the final path, as it's not regex.
Instead, do this (according to your example):
RewriteEngine on
RewriteRule ^cd2012/?$ cd2012/index.php
RewriteRule ^cd2012/(.*) cd2012/index.php?$1=1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ index.php?$1=1 [L]
RewriteRule ^([a-zA-Z0-9]+)$ index.php?$1=1 [L]
</IfModule>
Right now this is what does the magic for me.
Try this :
RewriteEngine on
RewriteBase /
RewriteRule ^cd2012/legal$ cd2012/index.php?legal=1 [L]
I have the following .htaccess file in my root:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
This works as it should for shortening all my URLs to website.com/something
The problem is Google can't find my robots.txt file in my root. The above file isn't letting it through. when It type website.com/robots.txt I get a 404 not found. But if I comment out the above .htaccess code I can get to it just fine.
How can I edit my .htaccess file to let robots.txt through without interfering with my other URLs?
RewriteEngine on
RewriteRule ^robots.txt - [L]
Second line will exclude robots.txt from URL rewritting rules .
Try above code
I tried both suggestions and they both work great. However I went with Kiran's answer simply because it's a shorter syntax. This is what I ended up with.
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
# remove trailing slash
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
# Allow Robots.txt to pass through
RewriteRule ^robots.txt - [L]
RewriteRule ^([^/]*)$ index.php?page=$1 [NC]
You can use this solution in your .htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php?page=$1 [L]
This rewrites all your requests to index.php?page=, except the files specified in the RewriteCond list.
Find the line that already exists in your .htaccess that says this:
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
And change it to this:
RewriteRule ^itemap.xml$ index.php?route=feed/google_sitemap [L]