I have seen several other threads about this but for some reason in my specific case the solutions are not working.
Here is the .htaccess
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1
The desired effect is that index.php will load what ever page is requested in the GET (/events-diary = index.php?page=events-diary) & that works fine.
However I have some REAL directories which need to be accessible for example /admin/
The above .htaccess works perfectly fine as desired on my home computer MAMP, it works perfectly fine on my Amazon Micro, it will not work on the deployment server ipage.com
When you enter /admin it will redirect to the root index. When you type /admin/index.php it works, but you have to specify the index.php
I cant figure out when it seems to be ignoring the !-d
UPDATE:
index.php contains the following PHP
if(!isset($_GET['page'])){
header("Location: home");
exit;
}
$line=page_content($_GET['page']);
note that this functions fine on the other 2 servers, i dont see why it would behave differently on the 3rd.
Use:
Options +FollowSymLinks -MultiViews -Indexes
With -MultiViews with uppercase V.
For Apache, in some cases upper/lower case are very important
Here is a different set of rewrite rules that might work for you:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)/?$ index.php?page=$1 [NC,L]
Are you trying to route things to /admin/index.php? If so, you could create a copy of your .htaccess, upload it to the /admin directory and set the RewriteBase to /admin.
or, if you wanted to turn the rewrite engine off in your /admin directory, you could create an .htacess file that contains:
RewriteEngine off
Difficult to post these suggestions in comment so resorting to an answer.
Try this rule:
ErrorDocument 404 default
ErrorDocument 403 default
DirectorySlash On
DirectoryIndex index.php index.html index.htm
Options +FollowSymLinks -Multiviews -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/$1 !-f
RewriteCond %{DOCUMENT_ROOT}/$1/ !-d
RewriteRule ^([\w-]+)/?$ index.php?page=$1 [L,QSA]
Related
I have a question.
I want to redirect domain.com/var to domain.com/id=var
I can do that, but when users write a var like my folders, the htaccess redirect to the folder first :/
This is my actual htaccess
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^([a-zA-Z0-9-+/]+)$ index.php?id=$1 [L]
RewriteRule ^([a-zA-Z0-9-+/]+)/$ index.php?id=$1 [L]
But when the user write for example css, the htacces redirecto to domain.com/css/?id=css
And the second problem is if the user put / after the var, example domain.com/var/
How can I change that? Thx 4 all!!
You need to skip files/directories from rewriting:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9+/-]+)/?$ index.php?id=$1 [L,QSA]
I have a website www.website.com and a few domains that redirect to this site. It's a masked redirect, so if I write www.domain.com I can see this url in the browser all the time, but it's actually redirected to subdomain.website.com What I'd like to do is do some .htaccess rewrite rule, so that everything that has domain domain.com will be rewrited to a local file on a server, that is outside of current folder. Let me explain folder structure here:
/
sub/
-- subdomain/
-- test/
---- index.html
web/
Currently everything from www.domain.com goes to /sub/subdomain. In the .htaccess file in /sub/subdomain I want to reroute the request to /sub/test/index.html. So in my .htaccess file in sub/subdomain folder I've tried this:
#start masked redirect
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
#RewriteBase /
RewriteCond %{HTTP_HOST} domain\.com$ [NC]
RewriteRule .. /test/index.html [L]
#end masked redirect
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Yes, I'm doing all this on top of Wordpress, which I don't really believe matters, but just to be sure I'm posting it.
Unfortunatelly I get Internal Server Error 500
What am I doing wrong, please?
Also: Please don't ask me why I am doing it like this, it has a reason, I'm not uncovering the whole thing I'm trying to do as it is irrelevant to this problem and I really want to focus on this issue here. I just want to know how to fix my .htaccess and it has to be this way. Thank you for your understanding.
This should be in sub/subdomain/.htaccess file
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\. [NC]
RewriteRule !^test/index\.html$ /test/index.html [L,NC]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Please can somebody take a look at my .htaccess code to help identify what's wrong.
I am trying to amend all example.php, example.html and example.htm URL's to index.php?filename=example.html
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(index\.php) - [L]
RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]
</IfModule>
When I enter a URL like example.html I'm taken to the default 404 and not index.php
Try:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
I'm not using the apache .hatacces for a while,
But try this one:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^.*/(css|img|js)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?filename=$1&%{QUERY_STRING} [L]
Basically what you need is to be sure that the URL didn't have already index.php. You accomplish it with RewriteCond.
After you redirect all to index.php passing the filename as a parameter.
You can add more exception to the RewriteCond like on this example, all content with /css, /js, /img will not pass to this rule.
You can check this thread: Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests also
So I've just upgraded to Laravel 4, and I'm setting things up on a new server. The default / route works fine, but every other route returns a 404 error. When trying index.php/route, I get the requested data, so that means that .htaccess isn't working.
Yes, AllowOverride is set to ALL.
Yes, I enabled the mod_rewrite module.
I have tried the following 3 .htaccess combinations:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
and:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
and:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And, after a server restart, and so on, none of them are working, and I'm still returning a 404 error.
Note: I am using several domains with the same laravel install, so my public folders are public/site1, public/site2, public/site3. However, I am routing the public paths to these folders, so I'm not sure that would be the problem.
Any thoughts?
I forgot to edit the vhosts in httpd.conf. Derp, derp.
Added:
<Directory "/var/www/public/site1">
AllowOverride All
</Directory>
to each of the site's vhost files, and it worked beautifully. Derp derp.
I have a mod rewrite working on localhost, but not in godaddy shared host.
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/WebShop/View/public%{REQUEST_URI} -f
RewriteRule ^(.*)$ WebShop/View/public/$1 [L]
RewriteRule ^(.*)$ entryPoint.php [QSA,L]
The problem is with the RewriteCond part. It cannot find the exsiting files in the subfolder. I tried with absolute path, relative path, rewritebase everything, but neither of them worked. Godaddy doesn't grant access to the rewritelog... Any idea how to solve this problem?
Edit:
The htaccess is in a subfolder, and in the document root is a htaccess which splits the request by domain into subfolders:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ %1/$1 [L,QSA]
And the real problem is, that the %{REQUEST_URI} in the htaccess of the subfolder contains the name of the subfolder too :S
Edit2:
Ok I have a partial solution:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%1/WebShop/View/public/%2 -f
RewriteRule ^(.*)$ entryPoint.php?file=%2 [L]
RewriteRule ^(.*)$ entryPoint.php [QSA,L]
This prints the file name if exists, but it's kind of joke, cause if I change the second rule to
RewriteRule ^(.*)$ x.php [QSA,L]
Then everything goes to the x.php. I'm wondering why mod rewrite never recognize the L flag?
(go drink a beer)
It's maybe because of some sort of strange directory settings, but if you redirect to a subDirectory on a godaddy server, you have to create there an empty .htaccess file with RewriteEngine On, otherwise it won't work.
The preceding code in the edit2 section works well, but not on a godaddy server... Here is the file access version of it:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/([^/]+)/(.*)$
RewriteCond %{DOCUMENT_ROOT}/%1/WebShop/View/public/%2 -f
RewriteRule ^(.*)$ WebShop/View/public/%2 [L]
RewriteRule ^(.*)$ entryPoint.php [QSA,L]
And I placed an empty .htaccess file with RewriteEngine On in the "WebShop/View/public" directory, that fixed the L flag problem.