Need some help with a rewrite please.
I have domain http://www.example.com. There are multiple folders within the root. I'd like to rewrite http://www.example.com/folder1/public/index.php to http://www.example.com/folder1
I dont have access to the main apache config so i'll need to do this in a .htaccess. If possible I'd also like to place the .htaccess inside folder1, not in the root.
Any help would be awesome, thanks.
Thinking monkey is close. Try:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /folder1
RewriteRule ^(?!public/)(.*) public/$1 [L]
You need the RewriteBaseand you need to stop recursive evaluation of the rule. The (?!public/) bit just means don't match anything already starting with public/. You need this sort of guard in .htaccess rules.
I presume you are trying to redirect any request to folder1 to folder1/public.
By that I mean, you want your URLs to look like http://www.example.com/folder1 while the actual URL will be http://www.example.com/folder1/public/index.php.
First of all, you have to use http://www.example.com/folder1 in your hrefs and rewrite this to http://www.example.com/folder1/public/index.php.
Add the below to your .htaccess residing in your folder folder1.
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
Related
I have already one blog running in root folder and I want to test another one in a sub directory called "test".
How do I make all links point to example.com/test/login.php and not example.com/login.php ? I don't want to edit all links in my files, I want this one behave as root so later no need to change anything when I put it in production.
I assume it can be fixed with .htaccess crazy Rewrite Module but I haven't figured it out yet so please help save my time!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} /test/ [NC]
RewriteRule !^test/ /test%{REQUEST_URI} [L,NC,R]
Reference: Apache mod_rewrite Introduction
i'm quite new to .htaccess file and I nees a bit of help..
I have a Greek site and I want to have urls like επικοινωνία.html. However, I haven't managed to translate successfully using htaccess file.
My code, for example, is:
Options +FollowSymlinks
RewriteEngine On
RewriteRule επικοινωνία.html contact.html
However, the url showing in the browser is not changing at all.
What am I missing?
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^επικοινωνία\.html$ /contact.html [L,B,R]
I'm trying to create a modrewrite rule that will change:
/blah/correct/xyz.htm
to
/correct/xyz.htm
There is not always /blah but when it's there, it always appears at the beginning of the URL. The URL can be any length, with numerous sub-paths. It could even be /blah/myfile.htm (which should just rewrite to /myfile.htm).
What's the best way to do this?
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule (?:^|/)blah(/.+)$ /$1 [L,NC]
This will internally forward /blah/foo to /foo or /blah/correct/foo to /correct/foo. If you want external rewrite then use:
RewriteRule (?:^|/)blah(/.+)$ /$1 [L,R=301,NC]
I have a single blog.php page that should get redirected from all these requests:
www.site.com/blog #goes to blog.php
www.site.com/blog/id-of-an-entry #goes to blog.php?id=id-of-an-entry
Also internationalised versions such for french:
www.site.com/fr/blog *# to blog.php?lang=fr
www.site.com/fr/blog/id-of-entry* #to blog.php?lang=fr&id=id-of-entry
What would be the more eficient and effective cond/rules for .htaccess? I've made many attemps but end walking in circles or with to many specialised rules :-) Thanks for any insights!
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^blog/([^/]+)/?$ /blog.php?id=$1 [L,NC,QSA]
RewriteRule ^blog/?$ /blog.php [L,NC,QSA]
RewriteRule ^([^/]+)/blog/([^/]+)/?$ /blog.php?lang=$1&id=$2 [L,NC,QSA]
RewriteRule ^([^/]+)/blog/?$ /blog.php?lang=$1 [L,NC,QSA]
I am not using this regulary so there can be better way but this could help you. Rules works like this. In () are your variables which corresponds to what you want to match. Than you can refer to them by $1 and so on. For example news/local would redirect them to file news-local.php you can use the same system to match you get variables.
RewriteRule ^([a-z]+)/([a-z]+)$ $1-$2.php
I have, let's say, www.website.org/folder/ which inside has the following .htaccess
RewriteEngine On
RewriteRule ^folder/[0-9]+ http://www.website.org/folder/index.php?n=$1 [NC]
inside folder I have many folders like 1234, 4567, etc. The behavior I'm looking for is a rewriting from www.website.org/folder/1234 to www.website.org/folder/index.php?n=1234. However, for some reason the rewriting doesn't occur and I get a Forbidden error (given that you can't access the directory itself).
How can I solve this?
Thank you very much
-- Note: I had to put away Options +FollowSymlinks because I was getting a Option FollowSymLinks not allowed here error from the provider's webserver.
-- Edit 1
Following Jason's post I modified the .htaccess as follows (I still kept it in folder):
RewriteEngine On
RewriteBase /folder/
RewriteRule ^folder/([0-9]+)/?$ /folder/index.php?n=$1 [NC,L]
But it still brings me to the folder, why is this? Thanks!
The way your rule is written, .htaccess should be in your webroot not the folder directory.
Alternatively, you could modify your RewriteBase. However, I'd do the above and use:
RewriteEngine On
RewriteBase /
RewriteRule ^folder/([0-9]+)/?$ /folder/index.php?n=$1 [NC,L]