I'm trying to upgrade an old PHP script to version 5 - the server is running 5.4.17. Links that worked before are not working anymore and I suspect the server. To determine the servers' guilt in this matter I need to understand a .htaccess file. Can you tell me what this does?
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^System/.*
RewriteRule ^(.*)?$ index.php?_path=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)?$ index.php?_path=$1 [L,QSA]
It routes all requests for either something in the System folder or for a file that doesn't exist to the index.php and setting the $_GET['_path'] variable to the request.
To check if this is the problem, try going to a URL like:
http://example.com/index.php?_path=something
where "something" is a page you used to be able to go to but is not working anymore.
Related
I have the following code in my .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} mysitedomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /web/$1 [L]
I'm currently using CPanel and CPanel does not allow you to set a new Document Root. So have my drupal files in my CPanel "public_html" directory with the composer.json files etc..and web directory that has all the Drupal related files. I am trying to get the site vistors to rewrite or redirect to www.mysitedomain.com/web for subsequent pages.. I tried the code below but does not seem to work.. Am i missing something?
To be specific.... I need the site to 1. load www.mysitedomain.com/web when www.mysitedomain.com is requested. 2. And ensure /web is is front of every subsequent request page request within the site (ie. www.mysitedomain.com/web/products should load instead of www.mysitedomain.com/products)
I am not sure what your question is, but I think you need something like this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
What it does: If the URL does not resolve to a file or directory in the present directory, put index.php in front of it.
I'd assume your index.php would then include the Drupal framework.
I would like to use htaccess for rewrite URL to pass 1 parameter like in this question. On this basis I tried to redirect.
My rewrite look like this;
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html?pg=$1 [L,QSA]
</IfModule>
Unfortunately this is not works and it redirects all urls to the main page (even non-existent too).
Could you help me please what did I wrong?
With your comment to the question it becomes clear what you are actually trying to do.
I assume this is what you are looking for, though I don't really understand what sense it makes to pass a HTTP GET aparameter to a html file...
RewriteEngine on
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule ^/?([\w]+) /index.html?pg=$1 [END,QSA]
This rule will work likewise in the http servers host configuration or in a dynamic configuration file (".htaccess"), you definitely should prefer the first option if you have access to the configuration.
Apart from that the rewriting module has to be loaded and enabled in your http host and, in case you decide to use a dynamic configuration file, you need to take care that it is located in the http hosts's DOCUMENT_TOOR folder and is readable for the http server process.
I run TYPO3 with a normal site and a subdomain in the same TYPO3 installation. On the normal site, automatically a mobile device is detected and then rerouted to the subdomain.
In my subdomain the visitor is redirected to the correct page in the TYPO3 tree, using following .htaccess file.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^m.mysite.com [NC]
RewriteRule ^(.*)$ http://m.mysite.com/index.php?id=74 [L]
What happens is that the visitor ends up in an endless loop where he is sent to the TYPO3 site and then to the subdomain and back again.
To get this working, I also need to change the working directory to www.mysite.com (I also have another provider where I can make these changes using a cpanel, and that site runs perfectly). I have been looking everywhere and have tried almost anything, but I simply do not have enough knowledge to change the working directory.
So what code should I use to change the working directory?
Use RewriteCond to not follow this rule for index.php.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^m.mysite.com [NC]
# Failing the index.php check, the usual test is to look for any
# existing file
# EDIT: Changed URI to start with / - should work per comments
RewriteCond %{REQUEST_URI} !^/index.php
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://m.mysite.com/index.php?id=74 [L]
I'm aware that there are a few questions on this subject already. I've trawled through them and can't make any of the proposed solutions work for me... maybe someone can help my specific problem?
I have a folder, parallax, in my app/webroot, containing index.html and associated files. This can be accessed just fine at /parallax/. However, if I try to access it at /parallax I get redirected to /app/webroot/parallax/, and ideally I'd like to suppress this behaviour.
Refactoring the whole thing as a CakePHP controller action isn't ideally something I want to get into (though if it might be simpler than I expect, let me know). The routes file doesn't as far as I know allow routing to a file in app/webroot.
The other port of call would seem to be the .htaccess file. I tried adding a rewrite rule:
RewritRule ^parallax$ parallax/index.html
or variations thereof, but the best I can get here is a page with broken images (whatever I'm ending up with, it doesn't seem to be able to find the images in the parallax/images subfolder any more).
Can anyone clear up my confusion and help me find the best route to /parallax giving the same result as /parallax/ does?
Please try the below .htaccess code in your root directory not in app directory.
<IfModule mod_rewrite.c>
RewriteEngine on
Rewriterule ^parallax/.*$ - [PT]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This should help you. What ever request start with parallax will be skipped by the .htaccess rule. And rest of the things will work as it is.
.htaccess root thanks to Anh Pham for this link it works perfectly http://www.balistupa.com/blog/2010/08/how-to-redirect-appwebrootblog-into-blog-wordpress-cakephp/
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/foldername.*
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/foldername.*
RewriteCond %{REQUEST_URI} !-d
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I tried to reproduce the situation but its working corretly for me. I'm using cakePhp 1.3 and both urls send me to index.html:
http://localhost:5013/parallax/
http://localhost:5013/parallax
My guess is that there's something weird on your .htaccess (the one located at /app/webroot/). Mine is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Basically, it tells the server that if the requested url is not a file (!-f) nor a directory (!-d), it will redirect the whole url as a parameter to /webroot/index.php , so cakephp will parse the url and call the controllers and all that..
Hope this helps
You should be able to put the parallax folder with a static index.html inside the app/webroot folder and have it be accessible by default at the /parallax/ url.
If you use relative paths you can even have you img/css for that page local to the folder and skip the usual cakephp paths entirely. No htaccess needed.
I have following rewrite rules for a website:
RewriteEngine On
# Stop reading config files
RewriteCond %{REQUEST_FILENAME} .*/web.config$ [NC,OR]
RewriteCond %{REQUEST_FILENAME} .*/\.htaccess$ [NC]
RewriteRule ^(.+)$ - [F]
# Rewrite to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^(/bilder_losning/|/bilder/|/gfx/|/js/|/css/|/doc/).*
RewriteRule ^(.+)$ index.cfm?smartLinkKey=%{REQUEST_URI} [L]
Now I have to exclude a script including its eventually querystrings from the above rules, so that I can access and execute it on the normal way, at the moment the whole url is being ignored and forwarded to the index page.
I need to have access to the script shoplink.cfm in the root which takes variables tduid and url (shoplink.cfm?tduid=1&url=)
I have tried to resolve it using this:
# maybe?:
RewriteRule !(^/shoplink.cfm [QSA]
but to be honest, I have not much of a clue of urlrewriting and have no idea what I am supposed to write. I just know that above will generate a nice 500 error.
I have been looking around a lot on stackoverflow and other websites on the same subject, but all I see is people trying to exclude directories, not files. In the worst case I could add the script to a seperate directory and exclude the directory from the rewriterules, but rather not since the script should really remain in the root.
Just also tried:
RewriteRule ^/shoplink.cfm$ $0 [L]
but that didn't do anything either.
Anyone who can help me out on this subject?
Thanks in advance.
Steven Esser
ColdFusion programmer
Please try to put the following line at the top of your config (after RewriteEngine on):
RewriteRule ^shoplink.cfm$ - [L]