I´ve made some RewriteRules in my .htaccess and they all work if I call my Website from the Domain/URL of my server.
Now I wanted to point an external Domain to my subfolder on my server where my Website is located, but all RewriteRules aren´t working anymore. When I call the php-files everything is alright, but when I call my "beautiful" links, I wanted to create, then only error 404 is shown.
This is currently my .htaccess file:
ErrorDocument 401 /401.php
ErrorDocument 404 /404.php
RewriteEngine On
#redirect www request to the base domain
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#ignore existing files and directories
RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
RewriteCond %{REQUEST_FILENAME} -d [NC]
RewriteRule .* - [L]
# Check if query string exists
RewriteCond %{QUERY_STRING} ^$
# Check that the request is not for an existing file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^spielplan$ spielplan.php [NC,L]
RewriteRule ^rangliste$ rangliste.php [NC,L]
RewriteRule ^alletipps$ allbets.php [NC,L]
RewriteRule ^benutzerseite$ userpage.php [NC,L]
RewriteRule ^einstellungen$ usersettings.php [NC,L]
RewriteRule ^spiel/([0-9]+)/?$ spiel.php?id=$1 [NC,L]
RewriteRule ^user/([A-Za-z0-9-]+)/?$ user.php?name=$1 [NC,L]
RewriteRule ^([A-Za-z0-9-]+)/?$ $1.php [NC,L]
I found a solution.
Because I tried to map my domain to a subfolder, this subfolder needs to work like an DocumentRoot and not like a subfolder.
So I needed to add:
RewriteBase /
in my .htaccess
Related
i have this htaccess file
DirectoryIndex index.php
#enable apache rewrite engine
RewriteEngine on
#set your rewrite base
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Deliver the folder or file if it exists on the server directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Push every request to index.php
#RewriteRule !\.(js|ico|gif|jpg|png|pdf|css|map|swf|flv|xml)$ index.php [QSA,L]
RewriteRule !\.()$ index.php [QSA,L]
RewriteRule ^(webroot)($|/) - [L]
it works but all files with the endings js,ico, ... have direct access.
now i need a htaccess that all request redirect to /
and i think this rule is important
RewriteRule !.()$ index.php [QSA,L]
but with one exception, all request they use the /webroot directory should not redirect (this is the folder with the images, css, js and so on)
I have no idea how to do this. I hope someone can help.
i found a solution:
DirectoryIndex index.php
Options -Indexes
RewriteEngine on
RewriteRule ^\.htaccess$ - [F]
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^(webroot)($|/) - [L]
RewriteRule !\.()$ index.php [QSA,L]
I using yii2 and I have a problem in .htaccess as below:
I can't access to js directory to use including files in my code.
ex: yii2/sepadmin/js/jquery.min.js net::ERR_ABORTED 404 (Not Found)
Here is my .htaccess:
RewriteEngine On
# deal with sepadmin first
RewriteCond %{REQUEST_URI} ^/yii2/(sepadmin)
RewriteRule ^sepadmin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^sepadmin/css/(.*)$ backend/web/css/$1 [L] #Accessible
RewriteRule ^sepadmin/js/(.*)$ backend/web/js/$1 [L] # Not Accessible
RewriteCond %{REQUEST_URI} !^/yii2/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} ^/yii2/(sepadmin)
RewriteRule ^.*$ backend/web/index.php [L]
As I mentioned the line, I can access css directory but I can't access js directory
I found the solution, I had to use directory name in REQUEST_URI as bellow.
RewriteEngine On
# deal with sepadmin first
RewriteCond %{REQUEST_URI} ^/yii2/(sepadmin)
RewriteRule ^sepadmin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^sepadmin/css/(.*)$ backend/web/css/$1 [L]
RewriteRule ^sepadmin/js/(.*)$ backend/web/js/$1 [L]
RewriteRule ^sepadmin/files/(.*)$ backend/web/files/$1 [L]
RewriteCond %{REQUEST_URI} !^/yii2/backend/web/(assets|css|js|files)/
RewriteCond %{REQUEST_URI} ^/yii2/(sepadmin)
RewriteRule ^.*$ backend/web/index.php [L]
My question is the same as: Zend Framework 2 without Vhost configuration but the solution didn't solve my problem.
I'm getting a customised 404 page.
my project is in a sub-directory, and I believe the .htaccess in the parent directory is stopping it from working.
note: I can't delete that one because there is another project running there
htdocs/.htaccess:
Options -Indexes
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteRule ^transcripts/$ https://spreadsheets.google.com/a/ci4tcm.com/ccc? key=0AodnCB9Mr1K1dFFmbGhOc3V4RjBvNzZxSE9EZ1dtSnc&hl=en#gid=0 [R,NC]
# ErrorDocument 404 /pages/404.html
# ErrorDocument 500 /pages/404.html
# ErrorDocument 403 /pages/404.html
# RewriteRule ^css(/)?$ / [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)$ /download/$1/$2/ [R]
# RewriteRule ^download/([A-Za-z0-9.]*)/([A-Za-z0-9.]*)/$ /download.php?test=$2&fol=$1
RewriteRule ^download/([A-Za-z0-9.]*)$ /download/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)/([A-Za-z0-9\+.-\s]*)$ /download.php?folder=$1&file=$2 [L]
RewriteRule ^download/([A-Za-z0-9.]*)$ /posters/$1/ [R]
RewriteRule ^download/([A-Za-z0-9\+.-\s]*)$ /images/wellbeing_posters/pdfs/$1 [L]
AddHandler server-parsed html
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ "http\:\/\/www\.another-domain\.com\/$1" [R=301,L]
# A bunch of redirect 303's here
# 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
htdocs/booking/ < Zend application here > (solution to other question).
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} = ""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
so my question is, how do I bypass the parent directory .htaccess rule when the user wants to enter the physical sub directory with the Zend Application?
Your edited question added a whole load of stuff to the .htaccess in the parent folder which changes things somewhat. Assuming you're able to edit that htaccess, the easiest thing to do would be to move the ZF rules into it. Just change any lines that include public and add c-booking before it. So as an example, the last line would look like:
RewriteRule ^c-booking/public/.*$ /c-booking/public/index.php [NC,L]
Also be aware that this is a less secure way to host an app. If you have any non-PHP config files, cache files etc. (things that would normally be outside the web root), make sure they aren't viewable through a browser.
I use a URL rewriting scheme of the following:
example.com/about/
example.com/this/is/a/page/
GOES TO:
example.com/pages/about/about.php
example.com/pages/this/is/a/page/page.php
It works fine, but on a 404 error, when typing in example.com/badpage/ it shows 404 page but changes the URL string to example.com/pages/badpage/badpage.php.
How to do keep the URL the same even on a 404 error?
(The htaccess also adds on '/' to the end of the URL requested as you can see from the code below)
htaccesss code:
DirectoryIndex /pages/index/index.php
ErrorDocument 404 /pages/error/404.php
RewriteEngine On
#Removes the www from domain for SEO
RewriteCond %{HTTP_HOST} ^www\.portal\.example\.com$ [NC]
RewriteRule ^(.*)$ http://portal.example.com/$1 [L,R=301]
# Don't fix direct file links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://portal.example.com/$1/ [L,R=301]
RewriteRule ^([A-Za-z0-9_-]+)/?$ pages/$1/$1.php [NC,L]
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ pages/$1/$2/$2.php [NC,L]
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ pages/$1/$2/$3/$3.php [NC,L]
RewriteRule ^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$ pages/$1/$2/$3/$4/$4.php [NC,L]
You need to add conditions before each of your rewrites to ensure you're not blindly rewriting into a file that doesn't exist. Mainly, the 4 rules at the end need to have some conditions:
RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_-]+)/?$
RewriteCond %{DOCUMENT_ROOT}/pages/%1/%1.php -f
RewriteRule ^ pages/%1/%1.php [NC,L]
The first condition creates a grouping which is backreferenced using %1. The second condition creates a path that you are trying to rewrite to and checks if that file exists using -f. Same thing for the others:
RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$
RewriteCond %{DOCUMENT_ROOT}/pages/%1/%2/%2.php -f
RewriteRule ^ pages/%1/%2/%2.php [NC,L]
RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$
RewriteCond %{DOCUMENT_ROOT}/pages/%1/%2/%3/%3.php -f
RewriteRule ^ pages/%1/%2/%3/%3.php [NC,L]
RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/?$
RewriteCond %{DOCUMENT_ROOT}/pages/%1/%2/%3/%4/%4.php -f
RewriteRule ^ pages/%1/%2/%3/%4/%4.php [NC,L]
I don't have much knowledge in .htaccess and I am struggling with regex concept in .htaccess.
I want same url concept as on facebook for user profile but dash(-), underscore(_), dot(.) this I want in url also currently my url rule is as follow:
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.][!pagenotfound|home|abuse/*|user/*|start/*|login/*|account/*|message/*|find/*|cms/*|accountactivation/*|register/*]*)/?$ memberspersonalinfo.php?members=$1 [QSA]
This pattern have some error
but when in my browser domain.com/username is comming it's working fine but when url will be domain.com/test-test or test_test or test.test it redirects to `PAGE NOT FOUND PAGE
and in my .htaccess rule defined to follow that rule like abuse/* have dynamic id wherever I have used star (*) they are referencing dynamic value. When I will do rule like
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.]*)/?$ memberspersonalinfo.php?members=$1 [QSA]
It's working fine but when I moveto home page then it calls memberspersonalinfo.php page it self.
I am trying to explain my Question again with htaccess script
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
DirectoryIndex index.html index.php
ErrorDocument 404 /pagenotfound
ErrorDocument 403 /pagenotfound
ErrorDocument 401 /slapme/pagenotfound
ErrorDocument 500 /pagenotfound
#index
RewriteRule ^index.html$ index.php [L]
RewriteRule ^index$ index.php [L]
RewriteRule ^home$ index.php [L]
#nopage
RewriteRule ^pagenotfound$ nopage.php [L]
#Regitration
RewriteRule ^register/createaccount$ userregistration.php [L]
#Regitration Confirmation
RewriteRule ^register/accountconfirmation$ registrationconfirm.php [L]
#Activation Regitration
RewriteRule ^accountactivation/([a-z,\_,A-Z,\_,\-,0-9]*)/([a-z,\_,A-Z,=,\_,\-,0-9]*)$ registrationactivation.php?UsercontactID=$1&AccountId=$2 [L]
#after login
RewriteRule ^user/main$ after_login.php [L]
#Payment Detail
RewriteRule ^user/myaccount$ useraccount.php [L]
#Logout
RewriteRule ^user/logout$ logoutuser.php [L]
#creategroup
RewriteRule ^start/creategroup$ http://domain.com/start/creategroup [L,R=301]
#Forgot Password
RewriteRule ^user/forgotpassword$ http://domain.com/user/forgotpassword [L,R=301]
#Login
RewriteRule ^login/userlogin$ http://domain.com/login/userlogin [L,R=301]
#Remove account
RewriteRule ^account/remove$ removeuseraccount.php [L]
#Send an email page
RewriteRule ^message/?$ contacttouser.php [L,QSA]
#Report any site user page
RewriteRule ^abuse/([0-9]*)/$ reportsiteuser.php?reportUserID=$1 [L,QSA]
#CMS FIND FRIENDS PAGE
RewriteRule ^find/friend$ http://domain.com/find/friend [L,R=301]
#CMS TERMS OF USE PAGE
RewriteRule ^cms/howitworks$ howitworks.php [L]
#CMS CREATE OWN SLAP PAGE
RewriteRule ^cms/createownslap$ createownslap.php [L]
#CMS BRAND OR PRODUCT PAGE
RewriteRule ^cms/brandorproduct$ brandorproduct.php [L]
#CMS APPS AND FEATURES PAGE
RewriteRule ^cms/appsandfeatures$ appsandfeatures.php [L]
this my full htaccess code everthing is working fine all rules are working but when i add
#group personal profile page page
RewriteCond %{REQUEST_URI} !/abuse(.*)
RewriteCond %{REQUEST_URI} !/user(.*)
RewriteCond %{REQUEST_URI} !/start(.*)
RewriteCond %{REQUEST_URI} !/login(.*)
RewriteCond %{REQUEST_URI} !/account(.*)
RewriteCond %{REQUEST_URI} !/message(.*)
RewriteCond %{REQUEST_URI} !/find(.*)
RewriteCond %{REQUEST_URI} !/cms(.*)
RewriteCond %{REQUEST_URI} !/accountactivation(.*)
RewriteCond %{REQUEST_URI} !/register(.*)
RewriteCond %{REQUEST_URI} !/social(.*)
RewriteCond %{REQUEST_URI} !/images(.*)
RewriteCond %{REQUEST_URI} !/css(.*)
RewriteCond %{REQUEST_URI} !/js(.*)
RewriteCond %{REQUEST_URI} !/userimages(.*)
RewriteRule ^([a-z,\_,A-Z,\_,\-,0-9.]+)/?$ memberspersonalinfo.php?members=$1 [QSA,L]
it always loads memberspersonalinfo.php