.htaccess rewrite rule? - .htaccess

I'm trying to rewrite my /index.php to /index, and my /register.php to /register, but it doesn't work!
This is my .htaccess:
RewriteEngine on
RewriteRule ^register/index$ register.php
RewriteRule ^index$ index.php
But... It isn't rewriting... Can someone tell me what I'm doing wrong?

RewriteEngine on
RewriteBase /
RewriteRule ^register/?$ register.php [NC,L]
RewriteRule ^index/?$ index.php [NC,L]
Adding Above code will make your the /register show /register .

I believe you're missing the preceding forward slashes:
RewriteEngine on
RewriteRule ^/register/index$ register.php
RewriteRule ^/index$ index.php
Check out the docs: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html#ToC2 - all of the examples have preceding forward slashes.

Related

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]

.htaccess mod_rewrite RewriteRule for categories

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]

.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]

htaccess rewrite url remove subdirectory

I'm trying to rewrite
http://www.example.com/directory/folder/*
to
http://www.example.com/directory/*
the htaccess file is in directory
this is my .htaccess file :
RewriteEngine on
RewriteBase /directory/
RewriteRule ^(.*)$ folder/$1 [L]
Any help would be much appreciated.
This is what I ended up doing :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)folder
RewriteRule ^(.*)$ folder/$1 [L]
What about this?
RewriteEngine on
RewriteRule ^folder/(.*) /directory/$1 [L]
Or you can go without [L] or use [R] instead.

CakePHP and .htaccess: how to redirect url with query string

I wanted to redirect this url from /main.php?page=pages&id=gettingpaidfortakingsurveys to /main/pages/getting-paid-for-taking-surveys.
Thanks!
[UDPATE]
i tested it on my existing cakephp .htaccess and it didn't work.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/main.php?page=(.+)&id=(.+) /main/$1/$2 [NC]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Since you appear to want to do this with Apache's .htaccess, you'll need the mod_rewrite module. In the .htaccess, you'll want something like:
RewriteEngine on
RewriteRule ^main.php?page=(.+)&id=(.+) /main/$1/$2 [NC]
This should get you /main/pages/gettingpaidfortakingsurveys. This won't hyphenate the word and I'm unsure you'll be able to do that without something overly complex.
Have you tried this, I'm assuming that this is a redirect for one page only. You'll need to put it above the Cake rewrite block. The second part must be the full URL:
Redirect 301 /main.php?page=pages&id=gettingpaidfortakingsurveys http://www.domain.com/main/pages/getting-paid-for-taking-surveys
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
If the rewrite is temporary, substitute 302 for 301.
The /main part of the url doesn't look very Cake-friendly. Shouldn't it just be /pages/...?

Resources