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.
Related
My current .htaccess file is as
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php [L]
This is at the directory level, I do not want to have a site-wide .htaccess.
I can redirect ../file.html to ../file.php but I am not able to do it for ../file -> ../file.php
My URL would be www.domain.com/sub1/sub2/file/ The file that should be run is www.domain.com/sub1/sub2/file.php But I want this rule to work only under sub2. So the rule will be included in the .htaccess at sub2
What exactly I need to change on this code to be able to do that?
More specifically, why is this not working?
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)$ $1.php [L]
This is working as I want it to work:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/?$ $1.php [L]
You can change your existing rule to this to work under /sub1/sub2/.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /sub1/sub2/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^./]+)/?$ $1.php [L]
i want to rewrite url like:
http://domain.com/index.php/subdirectory/subdirectory/
to:
http://domain.com/index.php
My rewrite rule look like this:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)
RewriteRule ^(.*)$ index.php$ [L]
thanks,
The RewriteCond
RewriteCond %{REQUEST_URI} !(.*)
will always been false, you don't need it. Just use :
RewriteEngine On
RewriteRule ^(.*)$ index.php [L]
How can I use htaccess to redirect a few static pages and keep the same url?
Example :
Redirect www.mydomain.com/url-that-remains.php to www.mydomain.com/page-number-23
My current htaccess file looks like that:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This code should work:
RewriteEngine On
RewriteRule ^url-that-remains\.php$ /page-number-23 [L,NC]
Try like this
RewriteEngine On
RewriteRule /somestaticpageonyourwebsite.html /yournewpage.html [R=302]
EDIT:
I don't know why the above doesn't work. This should work.
RedirectPermanent /somestaticpageonyourwebsite.html /yournewpage.html
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]