I have a site I administer but I inherited the code from a previous developer. He wrote some rewrite rules, most of which seem to do the necessary job.
However my client has now purchased a subdomain eg: http://shop.thesite.com
However running this in the browser just returns http://thesite.com
I have tried commenting out some of the rules to try and get the shop subdomain to work, but I cannot seem to do it.
Here are the contents of the htaccess file:
DirectoryIndex index.php index2.php index.html index.htm
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
#
########## End - Rewrite rules to block out some common exploits
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.xml|\.feed|\.ajax|\.img|\.xhtml|/[^.]*)$ [NC]
RewriteRule (.*) index.php [L]
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
<Files *.inc.php>
order allow,deny
deny from all
</Files>
<Files pagecounter.inc.php>
order allow,deny
allow from all
</Files>
<IfModule mod_php5.c>
php_value upload_max_filesize 50M
</IfModule>
<IfModule mod_php4.c>
php_value upload_max_filesize 50M
</IfModule>
I realise that is alot of code, and this is probably not the most enlightened question, but I would appreciate some help.
This was the line that I thought was rewriting the subdomain:
RewriteRule (.*) index.php [L]
I did comment that out but it made no difference, so now I am also wondering if I am having to deal with any caching issues.
Related
When users go to my sub domain, I want them to be redirected to a specific file I have in my subdomain. Or, to be exact, when someone goes here
http://app.example.com/
they should be redirected to here:
http://app.example.com/dashboard/
Everything I have tried doesn't seem to be working and the examples I have found online either don't work or don't do what I need them to do.
I'm also trying to get this to work from my root directory (from public_html). This is my file structue:
/ public_html
/ .htaccess
/ index.php
/ app.example.com
/ dashboard.php
You can see my htaccess file sitting on the top level. This is where I need to keep it.
This is my current file (including my attempt at the redirect):
# --------------------------------------------------------------------------------------------------------------------------------------
# Stops people from being able to see htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>
# --------------------------------------------------------------------------------------------------------------------------------------
# Options
Options All -Indexes +MultiViews
# --------------------------------------------------------------------------------------------------------------------------------------
# Redirect app.example.com to /dashboard
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.example.com
RewriteRule ^$ /dashboard [L,R=301]
# --------------------------------------------------------------------------------------------------------------------------------------
# Makes it so url can have slash at the end instead of .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
# --------------------------------------------------------------------------------------------------------------------------------------
# Adds wwww to url if it doesnt already have it
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
I've set up a Wordpress site.
I need to recursively remove the .php extension on files in a specific folder.
Say:
www.domain.com/wordpresspage/ (set up with permalinks, all good).
I then need to remove .php recursively for folder:
domain.com/gz/*
The content of domain.com/gz/ should have the .php extension removed. But only for this folder.
Folder structure
/
-/images (No .htaccess rules should apply, Wordpress takes care of it.)
-/downloads (No .htaccess rules should apply, Wordpress takes care of it.)
-/gz (.htaccess change, to remove .php file extension, overwriting Wordpress, in this particular folder)
-file1 (No .htaccess rules should apply, Wordpress takes care of it.)
-file2 (No .htaccess rules should apply, Wordpress takes care of it.)
Before I used the following .htaccess content to remove .php extensions, but now I need to only force this on one folder, since Wordpress is taking care of the rest.
#RewriteBase /
#RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php\ HTTP
#RewriteRule ^([^.]+)\.php$ https://example.com/$1 [R=301,L]
#RewriteCond %{REQUEST_URI} !(\.[^./]+)$
#RewriteCond %{REQUEST_fileNAME} !-d
#RewriteCond %{REQUEST_fileNAME} !-f
#RewriteRule (.*) $1.php [L]
I've tried a ton of things already, but the last few included:
Use the old .htaccess file that removes .php on all pages. This solves my path issue, but gives internal server error on the rest of the site.
Tried a gazillion ways of filtering out that folder recursively, to the point I'm no longer sure if it's even possible. (Don't even remember a fraction of what I tried).
Tried in the permalinks to add .php - but since it will redirect to remove it again, I'll get yet another Internal Server Error.
TL;DR - Can I recursively remove .php on a specific path in my .htaccess file, so Wordpress ignores this folder and let's it deal with it's own business?
Added after first round of help, my .htaccess file now looks like this:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
RewriteEngine On
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+\.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*)\.php$ /$1 [R=301,L]
# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AddType application/x-httpd-php-old .php
<IfModule security_module>
SecFilterEngine Off
</IfModule>
<IfModule security2_module>
SecRuleRemoveByID 1-99999
SecRuleRemoveByTag unoeuro
</IfModule>
After re-applying Permalinks, Wordpress adds this section to the .htaccess file:
# 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
Thanks in advance,
L
What you could do is the following
RewriteEngine On
# Only apply if no rewrite
RewriteCond %{ENV:REDIRECT_STATUS} ^$
# Only apply if request starts with /gz/
# followed by at least one character and ends with .php
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+\.php$
# Redirect to the same location but without .php ant the end
RewriteRule ^/?(.*)\.php$ /$1 [R=301,L]
# Only apply if request starts with /gz/ followed by at least one character
RewriteCond %{REQUEST_URI} ^/?gz/[^.]+$
# and the request it not a real directory
RewriteCond %{REQUEST_FILENAME} !-d
# and the request it not a real file
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite the request with .php at the end
RewriteRule ^(.*)$ /$1.php [L]
So if you request e.g. /gz/gz5.php is will be redirect you to to /gz/gz5
and if the request is /gz/gz5 it will rewite to /gz/gz5.php
I am building a wiki using dokuwiki, and am using the nice URL feature which uses url rewriting through Apache on the webserver, to get rid of the ugly php urls. My problem is that I seem to be only getting 404 Not Found errors when searching for the pages using the new URLs.
This is the .htaccess file provided, and the RewriteBase is pointed to the correct location.
#Options -Indexes -MultiViews +FollowSymLinks
## make sure nobody gets the htaccess, README, COPYING or VERSION files
<Files ~ "^([\._]ht|README$|VERSION$|COPYING$)">
Order allow,deny
Deny from all
</Files>
## Uncomment these rules if you want to have nice URLs using
## $conf['userewrite'] = 1 - not needed for rewrite mode 2
RewriteEngine on
RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
RewriteRule ^$ doku.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) doku.php?id=$1 [QSA,L]
RewriteRule ^index.php$ doku.php
## Not all installations will require the following line. If you do,
## change "/dokuwiki" to the path to your dokuwiki directory relative
## to your document root.
RewriteBase /dokuwiki
## If you enable DokuWikis XML-RPC interface, you should consider to
## restrict access to it over HTTPS only! Uncomment the following two
## rules if your server setup allows HTTPS.
#RewriteCond %{HTTPS} !=on
#RewriteRule ^lib/exe/xmlrpc.php$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
Make sure your Apache actually loads .htaccess files. You will probably need this in your Apache config:
AllowOverride All
I am in the process of moving an existing codeigniter website from a MediaTemple shared server to a Dreamhost VPS server. I have set up a mirror of the new server to view the site without switching the DNS; you can see it here
I have attempted to switch the DNS, but the problems persisted.
As you can see, it returns a 404 error. If I remove the htaccess file, the home page will come up, but none of the html pages will work. I think that this has to do with the RewriteCond and RewriteRule statements in the htaccess file.
Here is the htaccess file:
AddHandler php-stable .php
php_flag allow_url_fopen on
# php_flag extension_dir=/home/86983/data/lib/php
# php_flag extension=zip.so
Options +FollowSymLinks
RewriteEngine on
# RewriteCond $1!^(js|css|images|license\.txt|user_guide|admin|phpMyAdmin|uploads|ornaments_sitemap2_25_09\.xml|sitemap\.xml|robots\.txt|quickscript\.php|paypal_ipn\.php|test\.php|sitedown\.php)
# RewriteRule ^(.*)$ http://www.ornaments.com/sitedown\.php [L]
RewriteCond %{HTTP_HOST} ^ornaments\.com$ [NC]
RewriteRule (.*) http://www.ornaments.com/$1 [R=301,L]
RewriteCond $1 !^(admin|backupForPhpMyAdmin|blog|change_page_name\.php|css|favicon\.ico|images|index\.php|js|license\.txt|ornaments_sitemap2_25_09\.xml|paypal_ipn\.php|phpMyAdmin|uploads|quickscript\.php|robots\.txt|sitemap\.xml|sub-domains|test\.php|testblog\.php|url_checker|user_guide|tinymy\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
# RewriteCond %{HTTP_HOST} ^s86983\.gridserver\.com$ [NC]
# RewriteRule (.*) http://www.s86983\.gridserver.com/$1 [R=301,L]
#
# RewriteCond $1 !^(blog|index\.php|js|css|images|license\.txt|user_guide|admin|phpMyAdmin|uploads|ornaments_sitemap2_25_09\.xml|sitemap\.xml|robots\.txt|quickscript\.php|paypal_ipn\.php|test\.php|backupForPhpMyAdmin)
# RewriteRule ^(.*)$ /index.php/$1 [L]
Note: I did not build this site and am only slightly familiar with codeigniter and PHP in general. Any help would be greatly appreciated.
I suggest you copy in htaccess this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
#LoadModule rewrite_module modules/mod_rewrite.c
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
We solved this one by replacing the htaccess file with the one from the openCart part of the site that worked. That file looks like this:
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
# 2. In your opencart directory rename htaccess.txt to .htaccess.
# For any support issues please visit: http://www.opencart.com
Options FollowSymlinks
# Prevent Directoy listing
Options -Indexes
# Prevent Direct Access to files
<FilesMatch "\.(tpl|ini|log)">
Order deny,allow
Deny from all
</FilesMatch>
# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
RewriteRule sitemap.xml /index.php?route=feed/google_sitemap
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^?]*) /index.php?_route_=$1 [L,QSA]
### Additional Settings that may need to be enabled for some servers
### Uncomment the commands by removing the # sign in front of it.
### If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.
# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
#php_flag register_globals off
# 2. If your cart has magic quotes enabled, This may work to disable it:
# php_flag magic_quotes_gpc Off
# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
# php_value upload_max_filesize 999M
# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value post_max_size 999M
# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
#php_value max_execution_time 200
# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
# php_value max_input_time 200
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} ^www.shop.ornaments.com [NC]
RewriteRule ^(.*)$ http://shop.ornaments.com/$1 [R=301,L]
I am not clear on why it worked and what might still be broken that we can't yet see, but so far it looks good.
I just moved a development site from a virtual machine on my PC to a shared webhost in a subdomain and I'm getting a Forbidden error which I think is due to my .htaccess file. Currently I've got it set up like so:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Remove www prefix
RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [L,R=301]
# Redirect to remove .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
<Files ~ "\.inc$">
Order allow,deny
Deny from all
</Files>
I tried commenting out the RewriteBase line and the "remove WWW prefix" bit which doesn't seem to help. Currently my site resides at mysite.mysharedhost.com and I still need to be able to remove the PHP extensions from my files. Am I missing something important or do you think my error is unrelated to my .htaccess file? Thanks in advance!