I took over a hosting account for a friend to host a second domain on his server. All is good, except for the .htaccess file that was generated by whoever designed his first site.
The main site is: ra-pictures.com, hosted in the root folder /
The site I'm working on is posthumanmovie.com, which is hosted in the folder /posthuman
Here's the current .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
# route non-existant requests to single script
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^.*$ index.php [QSA,NS]
</IfModule>
When I try to go to posthumanmovie.com - I get a 404 not found error.
When I delete the .htaccess file, it works, but his other site ra-pictures.com has 404 errors on any page that isn't the index page. Any ideas on how I can change the .htaccess file to allow access to all pages from both sites?
Add a condition to check against the hostname:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ra-pictures\.com$ [NC]
# route non-existant requests to single script
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteRule ^.*$ index.php [QSA,NS]
</IfModule>
Related
I want to cancel an .htaccess rewrite that redirects people from mysite.com to mysite.com/blog.
I previously wanted to bypass the main page and send users straight to a subdirectory, so I added a rewrite. Now I want people to be able to access mysite.com, but still be able to reach mysite.com/blog (but only when they follow a link to mysite.com/blog, not by default). I'm a beginner to .htaccess, so I appreciate the patience and help.
Here's what was in my .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?dreamybeast.design$
RewriteRule ^(/)?$ blog [L]
I thought that just commenting out my rewrite code in the .htaccess file would stop the site from redirecting mysite.com to mysite.com/blog, but I'm still not able to land on mysite.com at all.
I also tried deleting the .htaccess file (there was nothing else in it) and I still can't land on the root url.
--- edit ---
There's an .htaccess file in the blog subfolder (which contains a Wordpress install) with the following code in it:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress
Is it possible that this is what's causing the redirect, not the .htaccess file in the root?
I have a CakePHP app that has some html static files in webroot.
HTML files are in some directories like webroot/dir1/dir2/page.html.
When I enter url: site.com/dir1 I get redirected to site.com/webroot/dir1/ but when I enter site.com/dir1/ I get redirected to the first page site.com
And If I enter url for the html file: site.com/dir1/dir2/page.html I get redirected to the first page site.com. It supposed to show the html file. How can I make it show html file and not redirect to first page?
In my public_html the htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
In the webroot the htaccess is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
It's definitely not connected to CakePHP. Just ignore your directory / ies that should not be processed by CakePHP's routing system, see this related SO post.
Insert .htaccess into your directory/ies that should be ignored:
RewriteEngine Off
your questions isn't about php,
it's about the apache Webserver or more about -> Apache Module mod_rewrite
Rewrite Engine is only called one time, so you have to put all changes in one File.
kind regards
set
I am working on a php redirect script which 302 redirects visitors to other sites when they access a redirect url..
The script gets a variable (id) from the url and then redirects the visitor to the specific page.
The url structure is : example.com/redirect/index.php?id=test
At the moment all redirects work if I use "ugly" urls, but I want to strip all unnessecary information out of the url with .htaccess rewrites for better usability.
Which .htaccess rewrite rules do I need to make the above shown urls look like : example.com/redirect/test
I am currently using the following .htaccess rules
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>
but they only work for urls like example.com/redirect/index.php?id=test if I try example.com/redirect/test I get a 404 error page.
It might be good to know, that I have 2 .htaccess files, one in my root directory and one in the root/redirects/ directory.
Best regards !
Try this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)?/?([^/]+)?/?([^/]+)?/? [NC]
I have my cakephp .htaccess files set up as in the cookbook and everything is working fine.
My web site currently has multiple domains, all of which point to the same site (e.g. www.site.com, www.site.co.uk). I'd like to set up a rule so that requests to www.site.co.uk/page are permanently redirected to www.site.com/page, etc.
I'm having trouble getting both rules to work together. Can anyone help me out?
EDITED TO INCLUDE FURTHER DETAILS:
Here is the .htaccess file in my web root:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
# Force domain to be www.site.com
RewriteCond %{HTTP_HOST} !^www\.site\.com$
RewriteRule ^(.*)$ http://www.site.com/$1 [R=permanent,NC]
# For CakePHP
RewriteCond %{HTTP_HOST} ^www\.site\.com$
RewriteRule ^(.*)$ app/webroot/$1 [NC]
</IfModule>
I also have a separate CakePHP app in a subdirectory: tbgroup. Here is the .htaccess file (tbgroup/.htaccess):
<IfModule mod_rewrite.c>
RewriteEngine on
# For CakePHP
RewriteRule ^(.*)$ app/webroot/$1 [NC]
</IfModule>
Everything works as fine: www.site.co.uk is redirected to www.site.com, www.site.co.uk/page is redirected to www.site.com/page. CakePHP works fine. The only problem is www.site.co.uk/tbgroup is not redirected to www.site.com/tbgroup - it remains as www.site.co.uk/tbgroup (and CakePHP works fine).
Try it out on the live site if you like (www.site.com or www.site.co.uk).
I believe that you've pointed out the answer in the permanent redirection link in your question.
It's really not related to cakephp. It's just mod-rewrite issue. You have yo put this code in your .htaccess file (under /app/webroot)
rewritecond %{http_host} ^(www.)?site.co.uk [nc]
rewriterule ^(.*)$ http://site.com/$1 [r=301,nc]
This is my .htaccess generated by wordpress that sits in my root directory.
I need to modify/add to it, to direct all incoming traffic to www.example.com, instead of example.com.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If someone wants to explain what all the above does also, that would be appreciated as well.
To do what you requested, you want to add:
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]
You can place that inbetween the <IfModule mod_rewrite.c> brackets after RewriteBase
As for what Wordpress' htaccess code does (didn't test it): It seems to test for any direct links to files and directories and not pass them through the RewriteRule which will normally take your link and send it to index.php
So if your link is for www.mysite.com/some/page, it makes sure /some/page isn't a direct file link or an actual web directory and if it isn't, then it passes the request to index.php which parses it to display the correct Wordpress page.