.htaccess mod_rewrite RewriteRule for categories - .htaccess

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]

Related

Add a specific part to url using .htaccess

I guess it's an easy question but I hardly know syntax used in .htaccess, so I got a bit stuck. How to add '/de/' after a domain name in this case, so the result will be something like 'blablabla.com/de/blog' or 'blablabla.com/de/offices' instead of 'blablabla.com/blog' and 'blablabla.com/offices'?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} lang=de [NC]
</IfModule>
I know that there should be RewriteRule after RewriteCond but, as I've said before, I'm not familiar with the syntax...
You can use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} lang=de [NC]
RewriteCond %{REQUEST_URI} !^/de/ [NC]
RewriteRule ^(.*)$ /de/$1 [R,L]
</IfModule>
To access your site urls with /de segment ,you can use :
RewriteEngine On
RewriteBase /
RewriteRule ^de/(.+)$ /$1 [NC,L]

rewrite flag [L] is not working

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]

Rewrite article.php?title=variable to variable/

I'm trying to redirect article.php?title=variable to variable/ using .htaccess but I'm not really sure what is wrong with my code. If I go to http://site.com/variable/ it is redirecting me to http://site.com/article.php//?titlu=article.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
#Rewrite urls for article
RewriteRule ^(.*)/$ article.php?titlu=$1
RewriteRule ^(.*)$ /$1/ [R]
</IfModule>
You have to capture the query string. This should work for you.
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} title=([A-Za-z0-9_.-]*)
RewriteRule ^article.php /%1/? [R=301,L]
I'm assuming you don't want to redirect slashes... if you do you could add them to the string as well (or accept all characters).
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} title=(.*)
RewriteRule ^article\.php /%1/? [R=301,L]

Issue with subdomains and htaccess for SEO

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

.htaccess not letting robot.txt through

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]

Resources