I got this problem and I have been tyring alot (even deleting the htaccess) and I haven't found a solution.
A customer of my company has an application that I didn't make.... but I could nottice that there was an HTACCESS (and it happened to me before) and it seems to have some Rewrite rules. I am not familiar with HTaccess stuff, I am very ignorant about what's going on in this kind of files.
The page looks like this
The htaccess file contains this:
Options All -Indexes
Options +FollowSymLinks
RewriteEngine on
#4 variables
Rewriterule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ $1.php?$2=$3&$4=$5&$6=$7&$8=$9
#3 variables
Rewriterule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/$ $1.php?$2=$3&$4=$5&$6=$7
#2 variables
Rewriterule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ $1.php?$2=$3&$4=$5
#1 variable
Rewriterule ^(.*)/(.*)/(.*)/$ $1.php?$2=$3
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
Do you have any idea if that is the HTACCESS FAULT? If I delete the HTACCESS I get a 500 Internal Server Error
This sounds like a relative/absolute URI issue. The images/scripts/css are probably linked using relative URIs which is broken when you have a structure like this: (.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/, while it could work fine when you access the page like this: /$1.php?something.
So you either need to change all of the links so that they're absolute URLs (that start with a /) or create a relative URI base at the header of all of your pages:
<base href="/">
Related
I have a simple file mydomain.com/business_nottingham.html
and i want to re-write that to an SEO friendly URL, eg mydomain.com/business-nottingham/
I've googled all the examples but they seem to be designed for either CMSes or PHP scripts.
Is there a simple .htaccess re-write example available that allows me to do something very simple as above?
Edit: I managed to find the following code finally
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]
However, it's still not quite working. If i enter the tidy URL, i get re-directed to a 404 page, but putting in the exact .html file name gets me to the right file but doesnt present me with a clean url.
I've tried various combinations of the above by reading various articles and tutorials but for some reason it doesn't seem to work for me.
You want to redirect only when the actual request is for an .html file, then you want to internally rewrite to the html file. The way URLs resolve is the browser shows where it thinks it's going (URL in the address bar), then the request is made to the web server. If the webserver (where the htaccess file is) wants to change what's in the browser's URL address bar, it needs to tell the browser to literally load an entirely different URL. The browser will then request the new URL. Then the server must internally rewrite that URL back to where the actual resource is (the first URL), but the browser doesn't see this happen.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|HEAD)\ /([^\ ]+)\.html
RewriteRule ^ /%2/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/(.*?)/?$
RewriteCond %{DOCUMENT_ROOT}/%1.html -f
RewriteRule ^ /%1.html [L]
im using shared hosting. i build my web application with codeigniter and my new web directory will be as follows:
/home/projName/public_html/proj_v3/
under this dir, there are index.php, .htaccess. as shown above, i separated different project version in different directories (ie: proj_v1,proj_v2, proj_v3). the web applications allows photo upload and it's stored in /home/projName/public_html/proj_v3/application/uploads. proj_v2 currently has the latest uploaded photo since it's still in use. because i have different version of projects, i want to place directory uploads in a common directory such as /home/projName/public_html. so that for any new version of projects, i won't have to move the upload folder to the new project folder. this might cause downtime.
currently, the .htaccess file in /home/projName/public_html/proj_v2 is:
Options -indexes
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1/ [L]
i have another .htaccess in /home/projName/public_html/ is:
Options All -Indexes
RewriteEngine On
Rewriterule ^(.*)\.*$ proj_v3/index.php/$1/
RewriteOptions MaxRedirects=3
basically how should i go about editing the 2nd .htaccess file in /home/projName/public_html/ so that if the web directory is domain.com/uploads/image.png, it gets the image from /home/projName/public_html/uploads. currently, the 2nd .htaccess file tells domain.com to point /home/projName/public_html/proj_v3
RewriteRule \.(jpe?g|gif|png|wmv|bmp)$ /uploads/$1
Might work for you. You can add other formats as needed.
What you want to do is allow the paths to real files and folders to exist, while redirecting everything else to CodeIgniter, and you can achieve this using this in your second .htaccess file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Definitely worth reading this article on the CodeIgniter website about mod rewrite
I actually gave a similar answer before: mod_rewrite in Users/<username>/Sites directory on OSX
I currently have this in .htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^page/(.*)/(.*)$ /type1/internal.php?parentFolders=$1&pageTitleID=$2 [L]
When I visit http://localhost/type1/page/home/play it works fine, however I would like to take the /page/ out therefore being http://localhost/type1/home/play
I have tried the following:
RewriteRule ^(.*)/(.*)$ /type1/internal.php?parentFolders=$1&pageTitleID=$2 [L]
however some images seem to vanish, and some don't.
Also, I find hard links in my nav do not work either as they are asking for variables used in internal pages.
I am not sure if this is a absolute/relative problem as my CSS is written as
<link href="http://localhost/type1/global.css" rel="stylesheet" type="text/css" />
and links seem to be full links when I inspect them with my browser!?
Any help would be great
As I understand the .htaccess file is located in /type1/ subfolder. Try these rules:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(.*)$ /type1/internal.php?parentFolders=$1&pageTitleID=$2 [L,QSA]
The (.*) pattern you are using is too broad for first parameter, I use ([^/]+) instead (any character except slash).
Added 2 rewrite conditions .. so only requests to non-existing files and folders will be rewritten. This should help with disappeared images (or may not -- it all depends how how the links are written).
Added QSA flag to preserve any existing query string.
I'm very new to Code Igniter (as in I just finished their "official" video tutorial), and I was wondering if there was a way to clean up the URLs just a little bit more.
Basically, is there some setting to keep the "index.php" out of the URL?
So instead of this...
http://localhost/codeigniter/index.php/blog/comments/
...you see this:
http://localhost/codeigniter/blog/comments/
Or do I have to rewrite the URLs myself with .htaccess?
Using an .htaccess is easier, other ways wouldn't probably work on shared hosting I guess.
That would do I guess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
Please follow the following instructions.
http://codeigniter.com/wiki/mod_rewrite/
As simple as 1 htaccess file and 1 modification to the config file
You don't "have" to use the htaccess but doing it any other way would be a whole mass of kludge (Think redirecting in php from .../index.php/... to the non index.php version).
Any php dev worth their salt would do it in the .htaccess.
Days later I asked about redirecting dynamic directories to index.php, and I got this code that works perfect (it's the only code I have in .htaccess):
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*) index.php
This translates urls like http://mydomain.example/dynamicdir/ to http://mydomain.example/index.php
Now I want to translate subdomains like http://dynamicdir.mydomain.example to http://mydomain.example/index.php?dir=dynamicdir
From examples I found in Internet I tried adding this line:
RewriteRule ^(.*)\.mydomain\.example index.php?dir=$1
But it doesn't work. I don't have enough experience with mod-rewrite to tell what's missing or wrong. Could you please help me to find a way to keep the dynamic directory translation, and add the catch-all subdomain rule?
Regards!
The mod_rewrite rules use the request path, which is relative to the virtual host. Try having different rewrite rules for each virtual host, but placing their documents in the same directory.
With RewriteRule you can only test the URL path. For the host name, you need to use %{HTTP_HOST} in a RewriteCond:
RewriteCond %{HTTP_HOST} ^(.+)\.example\.example$
RewriteRule ^ index.php?dir=%1