I want redirect all requested files from folder-a to folder-b. E.g. http://www.yoursite.com/folder-a/index.php to http://www.yoursite.com/folder-b/index.php.
How can I do that? I have verified if mod_rewrite works with this code:
RewriteEngine On
RewriteRule ^google.html$ http://www.google.com/ [R=301]
The structure on the webspace is the following:
.htacces
|-folder-a
|-folder-b
But if I want my folder redirect
RewriteEngine On
RewriteRule ^/folder-a/(.*)$ http://www.yoursite.com/folder-b/$1 [L,R=301]
the redirect doesn't work if I input the following URL:
http://www.yoursite.com/folder-a/
http://www.yoursite.com/folder-a/index.php
The redirect doesn't take place. I stay on the same page ... What I'm doing wrong? I also tried it with this htaccess:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^folder-a(.*)$ http://www.yoursite.com/folder-b$1 [L,R=301]
</IfModule>
If all this works I want to exclude some files. Eg. with this htaccess:
RedirectPermanent /folder-a/info.php /folder-b/new-info.php
Edit:
Now I tried this htaccess
redirectMatch 301 ^/folder-a/ http://www.yoursite.com/folder-b
This works, but I need something which takes the whole path and rewrite it to the new folder.
This for example doesn't work:
RewriteRule ^folder-a/(.*)$ folder-b/$1
Solution
I had an old htacess file in my folder-a so the redirect didn't worked. This is my final htaccess:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^folder-a/excludefile1.php http://www.yoursite.com/folder-b/newnameforfile1.php [L,R=301]
RewriteRule ^folder-a/excludefile2.php http://www.yoursite.com/folder-b/newnameforfile2.php [L,R=301]
RewriteRule ^folder-a/(.*)$ http://www.yoursite.com/folder-b/$1 [L,R=301]
</IfModule>
You probably need to put both rules in place: one for the empty folder and one for other files, and then the catch-all at the bottom. This is not tested:
RewriteEngine On
RewriteRule ^folder-a/info.php http://www.yoursite.com/folder-b/new-info.php [L,R=301]
RewriteRule ^folder-a/ http://www.yoursite.com/folder-b/ [L,R=301]
RewriteRule ^folder-a/(.*)$ http://www.yoursite.com/folder-b/$1 [L,R=301]
Related
I want to redirect several pages to a PHP page with GET variables. However, when I try to use an .htaccess file, it redirects but changes the URL. I don't want it to change the URL structure when redirecting. How would I do this?
For example, I want to redirect /fly-snooze-cruise to http://example.com/package_listing.php?package-type=fly-snooze-cruise
and /fly-snooze-cruise/orlando-airport to http://example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport
Here is my .htaccess code:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^fly-snooze-cruise$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise [L]
RewriteRule ^fly-snooze-cruise/orlando-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-airport [L]
RewriteRule ^fly-snooze-cruise/orlando-sanford-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=orlando-sanford-airport [L]
RewriteRule ^fly-snooze-cruise/melbourne-airport$ http://www.example.com/package_listing.php?package-type=fly-snooze-cruise&airport=melbourne-airport [L]
RewriteRule ^snooze-park-cruise$ http://www.example.com/package_listing.php?package-type=snooze-park-cruise [L]
how to write RewriteRule to access php file as html extension, the mark file is located inside folder called domain.com/markfolder/mark.php
and i got following in my root directory
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RedirectMatch 301 (.*)\.html$ $1.php
and below file i try to locate inside domain.com/markfolder/.htaccess
try 1
RewriteEngine on
RewriteRule ^mark\.php$ mark.html [NC,R]
try 2
RewriteEngine on
RewriteRule ^(.*)\.html $1\.php
try 3
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php [NC,L]
above three try simple doesn't work.
First, your htaccess file in your root directory is causing the problem. It's redirecting .html to .php and is part of mod_alias, not mod_rewrite. This means requests will get processed by both the RedirectMatch as well as any rewrite rules. So first change your root htaccess to:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L,R=301]
Not sure why you want to permanently redirect, since this will affect all requests even requests in subdirectories. It seems like it's not what you want and will only break any attempt for you to rewrite.
Then in the htaccess file in your markfolder:
RewriteEngine On
RewriteRule ^(.*)\.html$ $1.php [L]
I m sure that many people will say that this is duplicated but I try everything from other "Question"`s and nothings work for me.
The problem is that I move my project to the web server.
In this server I have folder "public_html" where I but my project Symfony.
Now to enter on my project I must write the following url: www.mydomain.com/Symfony/web/*
But I want to write a Rewrite Rule which will redirect from www.mydomain.com/Symfony/web/* to
www.mydomain.com/home/*.
To do this I try on 2 different ways with many combination of ReWrite rule.
In my public_html I create a .htaccess folder
I edit the .htaccess in Symfony/web folder
I add the following rule in both file but without success
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^Symfony/web/(.*)$ www.mydomain.com/home/$1 [L,R=301]
Unfortunately without success. What I`m doing wrong?
My htaccess file look like
And all the time Error 404 Object not found
Symfony/web/.htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteRule ^home/(.*)$ $1 [L,NC]
</IfModule>
It`s redirecting me but I receive again Object not found :(
I delete the .htaccess in public_html folder which is the root one for my server
public_html\.htaccess
RewriteEngine On
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
1: Place this code in /Symfony/web/.htaccess:
RewriteEngine On
RewriteBase /Symfony/web/
RewriteCond %{THE_REQUEST} \s/+Symfony/web/ [NC]
RewriteRule ^(.*)$ /home/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [L]
2: Place this code in /public_html/.htaccess:
RewriteRule ^home/(.*)$ /Symfony/web/$1 [L,NC]
I'm going to go out on a limb and say that your rule is backwards. I think you want your URL to be www.mydomain.com/home/* in the browser... In which case the rule would be reversed. Also, your .htaccess should be in the root and you don't need to include the domain in the rewrite rule because you set a rewrite base.
RewriteRule ^home/(.*)$ Symfony/web/$1 [L,R=301]
I just transfered my Domain to a new Server. Mod_Rewrite is enabled on the new server but unfortunately some RewriteRules don't work, while others do. I haven't changed anything in the .htaccess
So the URL www.mydomain.com/go/10.html should make an internal redirect to www.mydomain.com/go.php?name=10
The snippet in the .htaccess looks like this:
# go.php
RewriteRule ^go$ "$0/" [R=301,L,QSA]
RewriteRule ^go/$ go.php [L,QSA]
RewriteRule ^go/.*?([^\.\/]*)\.html$ go.php?name=$1 [L,QSA]
The $_GET["name"] is not available if I call this url.
Replace your .htaccess code with this.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(go)/([^.]+)\.html$ /$1.php?name=$2 [L,QSA,NC]
I have created a site in a subdirectory and would like the site to appear as if it's in the root.
I used the below Mod_Rewrite code to get the site root to redirect to the subdirectory, but I would like the folder the files are held in to not appear.
currently: www.example.com/sitefiles/content/
Would like: www.example.com/content
Thanks
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^$ /sitefiles/ [L]
RewriteRule (.*) /sitefiles/$1 [L]
If it needs to be done via .htaccess and mod_rewrite, then use this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/sitefiles/
RewriteRule (.*) /sitefiles/$1 [L]
Since you do not explicitly specify the page when website root will be hit, then there is no need for this line: RewriteRule ^$ /sitefiles/ [L]
You need to add condition for your main rewrite rule to prevent rewrite loop (when already rewritten URL gets rewritten again): RewriteCond %{REQUEST_URI} !^/sitefiles/
Well, the directory should have no reason to appear in any listing, and that mod_rewrite you posted should allow you to do as you said. Still, I would go about it a different way:
Options +FollowSymLinks +Indexes
RewriteEngine on
RewriteBase /
RewriteRule ^$ sitefiles/ [L]
RewriteRule ^(.+)$ sitefiles/$1 [L]
Hope this works.