I have an htaccess file under the main site
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php or .html extension
# To externally redirect foo.php ot foo.html to foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.(php|html) [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
That works for
http://www.site.com/tenant-referencing/
but I can't get the subsite to work
http://www.site.com/newwebsite/tenant-referencing/
I have the same htaccess under the subsite
Thanks
Related
My htaccess file is interfering with the implementation of Dropzone.js on my website. Here is the htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
#Force non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Options -Indexes
Basically I am forcing a non-www redirect and am hiding the .php extension from the URL. However, I did not know that that would interfere with Dropzone.js, which requires a file name in the action attribute of the form or in the url property of the Dropzone object.
How can I hide the .php extension without interfering with Dropzone.js?
Thanks to everyone! I took out the .php extension from the action attribute and like Enyo suggested that fixed it.
I'm hiding my file extensions with
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
When I navigate to this link
http://localhost/website/profile?user=user01&nofollow=1
I'm redirected here
http://example.com/folder/profile?user=user01
I've taken .php out of the url. Why does it redirect me?
Have it this way inside /website/.htaccess:
RewriteEngine On
RewriteBase /website/
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ $1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php[?\s] [NC]
RewriteRule ^(.+)\.php$ $1 [R=301,L,NC]
# Resolve .php file for extension-less php urls
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)$ $1.php [L]
Make sure to clear your browser cache before testing this.
Try using this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L,NE]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
I want to allow access to directories, while still maintaining the current configuration.
The Current configuration is this:
DirectoryIndex index.php Index.php
Options +FollowSymLinks -MultiViews
#Turn mow_rewrite on
RewriteEngine On
RewriteBase /
## hiding .php extensions, and externally redirecting /dir/file.php to dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
##internally redirecting /dir/file.php to dir/file
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
The thing is, this htaccess current configuration removes .php extension from files,
but i think, it's affecting directories, and restricting access to it.
Please what do i do to solve this
Try this code:
DirectoryIndex index.php Index.php
Options +FollowSymLinks -MultiViews
#Turn mow_rewrite on
RewriteEngine On
RewriteBase /
## hiding .php extensions, and externally redirecting /dir/file.php to dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NE]
##internally redirecting /dir/file.php to dir/file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
I want to get all my domains to rewrite and look good. for example:
example.com/blog.php?article=the-name-of-article
to become
example.com/blog/the-name-of-article
so i want the .php?article= to be changed into a /
my current .htaccess file looks like:
Options +FollowSymLinks -MultiViews
rewriteengine on
RewriteBase /
## Hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
but all that does is drop the .php
I have been searching around but I just want to hear how everyone accomplishes this so easily.
RewriteRule ^blog/(.*)$ blog.php?article=$1 [QSA,L]
You had a great response that helped me resolve my .htaccess issue on GoDaddy. This was the code you provided:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
QUESTION: How can I exclude a file and/or directory from being rewritten?
Thanks!
David
Assuming you don't want to redirect /ignore.php. Modify above code like this:
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteCond %{REQUEST_URI} !^/ignore\.php$ [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !^/ignore$ [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]