godaddy - htaccess condition not working - .htaccess

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.

Related

RewriteCond %{REQUEST_FILENAME} !-d not working

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]

How do I do simple flat link to .php file redirect?

My current .htaccess file is as
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php [L]
This is at the directory level, I do not want to have a site-wide .htaccess.
I can redirect ../file.html to ../file.php but I am not able to do it for ../file -> ../file.php
My URL would be www.domain.com/sub1/sub2/file/ The file that should be run is www.domain.com/sub1/sub2/file.php But I want this rule to work only under sub2. So the rule will be included in the .htaccess at sub2
What exactly I need to change on this code to be able to do that?
More specifically, why is this not working?
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^(.*)$ $1.php [L]
This is working as I want it to work:
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/?$ $1.php [L]
You can change your existing rule to this to work under /sub1/sub2/.htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /sub1/sub2/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^./]+)/?$ $1.php [L]

.htaccess how to remove subdirectory?

I have a website in which I want to enter
http://mysite.com/myfolder
but go to (load index.php from)
http://mysite.com/dir/myfolder
So which kind of RewriteRule should I use?
The following rule didn't work and it caused an "500: Internal Server Error" in all pages.
RewriteRule ^$ dir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ dir/$1
Thanks !
The following should work as long as no path includes the "dir" string:
RewriteEngine On
RewriteCond %{HTTP_HOST} !dir
RewriteRule ^(.*)$ http://mysite.com/dir/$1 [R=301,L]
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 (?!^dir/)^(.*)$ /dir/$1 [L,NC]

htaccess RewriteCond for subdirectory not working

I have my .htaccess file written as such for my main program in the top directory but also want to exclude a sub-folder where I want to run another program.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond {REQUEST_URI} !=/ecart
RewriteRule ^files/ - [L]
RewriteRule ^(.*)/$ index.php?layers=$1 [L]
</IfModule>
I am trying the RewriteCond but it's not working.
It should go to the ecart/index.php file but still I am being brought to the front domain when I put my address in as www.mydomain.com/ecart
Your code has syntax error with logical errors. {REQUEST_URI} has missing % sign and RewriteCond is applicable to next RewriteRule only. Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/ecart(/.*|)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/?$ /index.php?layers=$1 [L,QSA]

htaccess redirection and rewrite from php to html

I am stuck with .htaccess modification, need a little help.
First off, here is whats inside my htaccess.
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]
For example, I created the file named test.php and uploaded to my server.
I want my server to behave like this.
http://example.com/test/test.html -> http://example.com/test/test.html(as it is)
http://example.com/test/test.php -> http://example.com/test/test.html
but with the .htaccess I have right now,
I still have both .php and .html which may be considered as file duplication by search engine crawler like Google robot (isn't it?).
Any help appreciated.
try this .htaccess code
# Enable Rewrite Engine
RewriteEngine on
#Create friendly URL
RewriteRule ^test/(.*)\.html$ test/$1\.php [L]
OR
RewriteCond %{REQUEST_URI} ^(.*)\.php$
RewriteRule ^(.*) /$1.html [L]
OR
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## .php to .html
# To externally redirect /test/test.php to /test/test.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1.html [R,L,NC]
This is a configuration file of apache '.htaccess' if you still want to configure then change
RewriteEngine on
I hope this work
You may try this in one .htaccess file in root directory:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !\.html [NC]
RewriteRule ^([^/]+)/([^.]+)\.php /$1/$2.html [R=301,NC,L]
For silent mapping, replace [R=301,NC,L] with [NC,L]

Resources