Allowing access to dev site via htaccess - apache

I have inherited a Prestashop website and the htaccess file is set up for all the required redirects. I want to allow access to the dev subdomain but the htaccess keeps redirecting to main site. I have tried to allow access with my limited knowledge and research from the web, but I get a 500 error when I upload the edited file.
the original rewrites are like so
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.mysitename.com$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^www.mysitename.com$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^www.mysitename.com$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404
I have tried to add at the beginning after
RewriteCond %{HTTP_HOST} ^www.mysitename.com$
these lines
RewriteCond %{HTTP_HOST} ^dev\.mysitename.com$
RewriteRule ^/(.*) http://dev.mysitename.com/index.php/$1 [L, QSA]
But I just keep getting a 500 error and can't experiment as it takes the site offline.

Your new lines are going between an existing RewriteCond and RewriteRule pair and breaking their syntax. Try moving your lines above the RewriteCond %{HTTP_HOST} ^www.mysitename.com$ line.

Have it this way:
<IfModule mod_rewrite.c>
<IfModule mod_env.c>
SetEnv HTTP_MOD_REWRITE On
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mysitename\.com$
RewriteRule . - [E=REWRITEBASE:/]
RewriteRule ^api/?(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^www\.mysitename\.com$
RewriteRule !(?:^|/)index\.php$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
#If rewrite mod isn't enabled
ErrorDocument 404 /index.php?controller=404

Related

How can I use .htaccess to hide extension and prevent user access with extension url?

here is my code for hide .html and .php extension when user view my site, http://example.com/xxx.html to http://example.com/xxx
But I hope to make user when they input http://example.com/xxx.html, they cannnot access and jump to 404 not found.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/ [R=301,L]
# Remove .php-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^\.]+)/$ $1.php
# Remove .html-extension from url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^([^\.]+)/$ $1.html
# End of Apache Rewrite Rules
</IfModule>
Anyone have solution?
You can add this as your first rule:
RewriteCond %{THE_REQUEST} \.(?:html|php)\s [NC]
RewriteRule ^ - [R=404,L]
Update
Perhaps this will fix your ErrorDocument problem:
RewriteCond %{THE_REQUEST} \.(?:html|php)\s [NC]
RewriteCond %{REQUEST_URI} !=/error404.html
RewriteRule ^ - [R=404,L]

.htaccess restrict ip to url

Im trying to restrict access to the /admin path (Not actual directory) on my web server to a set of IP address'. Here's what i have now, however it doesnt seem to set function as expected.
This is for Craft CMS, below is my .htaccess file sitting in /public_html.
<IfModule mod_rewrite.c>
RewriteEngine On
SetEnv HTTP_MOD_REWRITE On
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Send would-be 404 requests to Craft
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
RewriteRule (.+) index.php?p=$1 [QSA,L]
RewriteCond %{REQUEST_URI} ^/admin
RewriteCond %{REMOTE_ADDR} !^10.6.
RewriteCond %{REMOTE_ADDR} !^192.168.
RewriteCond %{REMOTE_ADDR} !^172.17.
RewriteRule (.*) / [R=301,L]
</IfModule>

Apache htaccess - route all requests to index.php except those to certain directories

Currently, my .htaccess file is routing all requests where the file does not exist to index.php. I would like to alter this so that it routes all requests to index.php regardless of whether or not the file exists, except for certain directories/paths. (such as /js, /css, /img)
Here is my current configuration:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm having trouble figuring out how to do this with the Google or apache's documentation. Help is much appreciated, as are any general tips on this issue.
The following should work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} ! ^/css/ [OR]
RewriteCond %{REQUEST_FILENAME} ! ^/img/ [OR]
RewriteCond %{REQUEST_FILENAME} ! ^/js/
RewriteRule . /index.php [L]
</IfModule>

Annoying Silex subdirectory .htaccess issue

I'm working on a few projects using Silex and on none of them can I get the .htaccess file working. The current directory structure is http://localhost/IIV/
The front file in Silex is in http://localhost/IIV/web/index.php
This is what I have currently:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /IIV/
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^ - [L]
RewriteCond %{DOCUMENT_ROOT}/web/$1 -f
RewriteRule ^(.+?)/?$ /web/$1 [L]
RewriteCond %{DOCUMENT_ROOT}/web/$1 !-f
RewriteRule ^(.+?)/?$ /web/index.php [L]
RewriteRule ^(.+?)/?$ /web/index_dev.php [L]
Your RewriteBase is wrong, try this:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /IIV/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
Also, make sure Apache is configured to load the .htaccess rules as #Maerlyn mentioned above.

hide file extension in url by htaccess

I want to hide my file extensions in browser to be displayed, like http://www.example.com/dir/abc.php should be displayed as http://www.example.com/dir/abc only.
i wrote following rewriteCond and rewrite rule on .htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ /$1.php [L,QSA]
but this code doeesn't seems to helping me.
EDIT:
this is complete code of my htaccess file
Options -Indexes
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?127.0.0.1 [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?127.0.0.1.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost.*$ [NC]
RewriteRule \.(js|css|jpg|png)$ - [F]
RewriteEngine on
RewriteRule ^(.*)\.[\d]{10}\.(css|js|png|jpg)$ $1.$2 [L]
RewriteEngine On
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
COMPLETE .htaccess:
Options +FollowSymLinks -MultiViews
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
RewriteEngine on
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# To internally forward /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
# block direct hot linking
RewriteCond %{HTTP_REFERER} !^http://(www\.)?127.0.0.1 [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?localhost [NC]
RewriteRule \.(js|css|jpg|png)$ - [F]
RewriteRule ^(.*)\.[\d]{10}\.(css|js|png|jpg)$ $1.$2 [L]
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
I'm not an Apache expert by any stretch, but I'm curious why no one is recommending the negotiation module (mod_negotiation). Are there best-practice reasons to avoid using
I heard about it in passing at http://www.webhostingtalk.com/showthread.php?t=317269. After enabling mod_negotiation in my global configuration:
LoadModule negotiation_module /usr/lib/apache2/modules/mod_negotiation.so
I just had to enable it in my virtualhost's Options. Here's the whole config block:
DocumentRoot /var/www/site_directory/public_html
ServerName your.domain.here.com
<Directory /var/www/site_directory/public_html>
allow from all
Options +Indexes Multiviews
</Directory>
easy method is:
you create your link like
'Home' instead of 'Home'
Then your .htaccess should be like this:
RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-l
RewriteCond ^home home.php [L]
The simplest and easiest way:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]