I have a .htaccess in my root of website that looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.pl [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?([a-z0-9_-]+)\.mydomain\.pl [NC]
RewriteRule ^/?$ /index.php?run=places/%1 [L,QSA]
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{REQUEST_URI} !^/upload/
RewriteCond %{REQUEST_URI} !^/javascript/
RewriteRule ^(.*)$ /index.php?runit=$1 [L,QSA]
But when I type:
mydomain.pl/guests
I would like to go normally to actual folder guests. I understand that I need to somehow disable this rule for guests subfolder, but how do I do this?
EDIT:
I've included whole .htaccess file
I've put a htaccess in subfolder and added RewriteEngine Off and it works.
Add one of these
RewriteEngine On
#If the request starts with guests, then pass it through
RewriteCond %{REQUEST_URI} ^guests
RewriteRule ^ - [L,QSA]
#Or, if the request contains an existing filename or directory, pass it through
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L,QSA]
Related
This is my current htaccess.
Site
|.htaccess
|--/folder-1
|--/folder-2
Now my root htaccess is as follows:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^/?$ /public/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*) /public/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I want users to access all files and folders inside folder 1 and folder 2. How that can be done?
Several changes: do your domain redirect first (note the subtle changes);
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule .* http://%1/$0 [R=301,L]
RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!(?:folder-1|folder-2)(?:$|/)|public/(?:index\.php)?$).* public/$0 [L]
This incorporates the folders you're excluding from rewriting into the main rule, so should be more efficient. It looks ugly since it starts with a negative look-ahead assertion (?! and the rest of the groups begin with (?: so they are non-capturing.
Do you really need a single domain? If so, it should be checked on all requests. If not, drop the first RewriteCond of the second RewriteRule.
if your default document is not index.php, change it in the negative look-ahead assertion of the second RewriteRule.
I want to rewrite my main domain to a path and if no query is appended then to a different path. I have a wildcard C name in place to support subdomains.
www.xxx.com => works normally
abc.xxx.com => point to a folder
abc.xxx.com/abc-xyz => point to www.xxx.com and should work normally
This is what i have right now :
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$
RewriteRule ^$ portfolio/index.php?pageDetailId=%1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_HOST} !^([w]{3,3}[.]{1,1}){0,1}example.com$
RewriteCond %{HTTP_HOST} ^([0-9a-zA-Z-]*)[.]example.com$
RewriteRule ^(.*)$ $1?pageDetailId=%1 [QSA,L]
</IfModule>
As we can see, i need that abc as variable in abc.example.com/abc-xyz. Please reply with doubts with any, i tried many ways its not working. This same htaccess works on 1 domain smoothly but when i created a new domain its not working on that. Thanks.
NOTE: It works on httpd but not on apache2
Have it like this:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^(?!www\.)([\w-]+)\.example\.com$ [NC]
RewriteRule ^(index\.php)?$ portfolio/index.php?pageDetailId=%1 [NC,L,QSA]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^(?!www\.)([\w-]+)\.example\.com$ [NC]
RewriteRule ^(.+)$ index.php?pageDetailId=%1&/$1 [L,QSA]
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
I want something like this:
If a request comes to domain.com/photos/1.jpg it should read file from new_photos/1.jpg directory. But url should still look same. I tried with this line to do this:
RewriteRule ^photos/(.*)$ new_photos/?$1
It doesn't work. How can I fix it?
Edit:
My full htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php/?$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/?$1 [QSA,L]
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteRule ^robots\.txt$ robots-subdomain.txt
If the file is in /new_photos dir ,You can use this :
RewriteRule ^photos/(.*)$ new_photos/$1 [NC,L]
I'm trying to do rewrite only for a subdirectory, but I have a problem with RewriteCond.
All my files are in /abc.
Here is my htaccess (/abc/.htaccess) file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} ^/static/ [NC,OR]
RewriteCond %{REQUEST_URI} ^/files/ [NC]
RewriteRule . - [L]
RewriteRule (.*) index.php?_url=$1 [QSA,L]
So I want to rewrite every url to index.php except the existing files in /static and /files. But this code is rewriting /static/a.jpg too, since the request was /abc/static/a.jpg. I tried setting RewriteBase to /abc/, but nothing changed.
Any idea how can I solve this?
Have your .htaccess like this in /abc/.htaccess:
RewriteEngine on
RewriteBase /abc/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_URI} ^/(static|files)(/|$) [NC]
RewriteRule . - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?_url=$1 [QSA,L]
I have been trying to redirect to a different folder with .htaccess when I hit a domain.
Here's my .htaccess redirect rule, can you tell me where am I wrong?
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond %{HTTP_HOST} ^(www.)?racereadymotorsports.in$
RewriteRule ^(.*)$ /raceready/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www.)?annelies-slabbynck.com$
RewriteRule ^(.*)$ /annelies/$1 [L,R=301]
So, what I want is, if someone visits racereadymotorsports.in, they redirect to /raceready/ directory
and on the other hand if they visit to annelies-slabbynck.com, they should redirect to /annelies/ directory
At present, this redirects twice for annelies-slabbynck.com which means that, I end up with:
http://www.annelies-slabbynck.com/annelies/annelies/ as my final url
I am running a shared hosting and do not have access to add a new configuration.
Please help.
You need to remove the [OR] flag and reproduce the same conditions with the other rule. Maybe something like:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?racereadymotorsports.in$
RewriteRule ^(.*)$ /raceready/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?annelies-slabbynck.com$
RewriteRule ^(.*)$ /annelies/$1 [L,R=301]
Or better yet, you can use these conditions instead: RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?racereadymotorsports.in$
RewriteCond %{DOCUMENT_ROOT}/raceready/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/raceready/$1 -d
RewriteRule ^(.*)$ /raceready/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www.)?annelies-slabbynck.com$
RewriteCond %{DOCUMENT_ROOT}/annelies/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/annelies/$1 -d
RewriteRule ^(.*)$ /annelies/$1 [L,R=301]
Note that the R=301 flag in your second rule redirects the browser, unlike the first rule which only internally rewrites the request.