I already wrote yesterday about a problem with .htaccess that I solved thanks to the help of the user #RavinderSingh13. Now another small problem has arisen. I made sitemap.php which takes care of creating a sitemap by retrieving files from mysql database. Now I need to convert sitemap.php to sitemap.xml. But the .htaccess file does not allow me to find the requested file.
currently my .htaccess is this:
RewriteEngine ON
##Excluding Indexes and MultiViews options here.
Options -Indexes -MultiViews
DirectoryIndex home.php
##Rule for adding / at end of urls.
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
##Rules for non-existing pages to be served here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ core.php [QSA,L]
i added this, but unfortunately it doesn't work
RewriteRule ^sitemap\.xml$ sitemap.php [L]
the sitemap.php file is located in the main root of the site. Could someone help me. Many thanks in advance.
Related
I am currently building a PHP-based portfolio site without any frameworks whatsoever. I have created an index.php file in the root and a lot of folders namely /about, /contact, /portfolio and the like. Within each of those, I have a separate index.php file
I created a .htaccess file and in it, I have this code...
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
For some reason when I visit my site at example.com/index.php or example.com/about/index.php the .htaccess file is not working and removing it.
Any ideas why?
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
If the intention with these directives is to remove index.php from the requested URL then you are using the wrong rules! This rule would route a request for /something to index.php/something (passing the requested URL-path as path-info to index.php) providing /something does not map to a file or directory.
You have presumably structured your URLs so they map to filesystem directories from which the DirectoryIndex is served, so the above directives would seem to be entirely redundant. (?)
To remove index.php from the end of any URL
To remove index.php (the DirectoryIndex) from any URL you would need to do something like the following instead:
RewriteRule ^(.+/)?index\.php$ /$1 [R=301,L]
Test first with a 302 (temporary) redirect to avoid potential caching issues.
To clarify...
you must not be linking internally to /index.php or /about/index.php. The above directive is only for when a user or external site erroneously requests the index.php file directly.
And include trailing slashes on your internal links. eg. you should be internally linking to /about/ and /contact/ etc. (not /about or /contact), otherwise mod_dir will implicitly issue a 301 redirect to append the trailing slash.
It took a while and thanks for the suggestions by Mr White this is my solution..
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
Works perfectly now.
Thank you for everyone who took the time out to help me on this.
I'm trying to get a webpage running which might not get any support anymore, so I have to fix this on my own. So in the root directory, I have this .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*) resources/$1 [L]
So all the content gets redirected to the resources/ folder. Now this kinda works, as the frontpage shows all the static content (CSS, JS, Images). But when I try to open mydomain.com/admin, I'll get an HTTP 500. The logfile says
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
The .htaccess file in the sub-dir has this content:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?param=$1 [QSA,L]
For my basic Apache knowledge this does seems quite right; but is it, or do I have change Apache settings? (The VPS is a kind of PaaS-thing, so I can access/change some things)
Thank you.
Have your root htaccess rule file in following way(you need to put a condition for a check before rewriting).
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/resources [NC]
RewriteRule ^(.*)$ resources/$1 [L]
Then for your sub directory level htaccess file try following:
Options -MultiViews
RewriteEngine On
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?param=$1 [QSA,L]
Also in case you want to apply same rules which you have in your root directory to sub-directories then add RewriteOptions InheritBefore before RewriteEngine ON in your sub directory level htaccess file.
So I need to do a .htaccess file that allow me to redirect the images link folder (wp-content/upload/) from a different site (http://widesigner.com.br/alessandra/) to be this one (http://www.alessandratonisi.com.br/site/)
Basically it's redirect some image links, example:
http://www.widesigner.com.br/alessandra/wp-content/uploads/2012/03/MG_6058-600x400.jpg
http://www.widesigner.com.br/alessandra/wp-content/uploads/2012/03/MG_9515.jpg
to
http://www.alessandratonisi.com.br/site/wp-content/uploads/2012/03/MG_6058-600x400.jpg
http://www.alessandratonisi.com.br/site/wp-content/uploads/2012/03/MG_9515.jpg
So what you need is redirect a website domain to another one for a specific folder. I don't know if the next line will help you to solve the problem, I don't think that will be the solution since I didn't test it.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/alessandra/(.*)$
RewriteRule ^(.*) https://www.alessandratonisi.com.br/site/%1 [R=302,NC]
Here are a lot of examples that could lead you to the correct answer: https://gist.github.com/ScottPhillips/1721489.
UPDATE:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/alessandra/(.*)$
RewriteRule ^(.*) https://www.alessandratonisi.com.br/site/%1 [R=302,NC]
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
I'm using codeigniter, and I tried to remove index.php from url by creating .htaccess file
and it contents:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
this way is working will at xampp server.
but when I uploaded the site, unfortunately there was a problem appeared:
I have a folder called files and it content sub folders: images, css, js, swf, upload.
and every file at those folders can't view, and the browser said there the file not found.
any help ploese.
Just make sure you exclude those too:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css|swf|upload)
RewriteRule ^(.*)$ /index.php/$1 [L]
This is my .htaccess file. My understanding is that for any file or directory which has access attempted and doesn't exist, it will forward onto Codeigniter.
Anything which does exist will work fine and will not require individual exclusion. This will save time and hassel each time you add a new directory or folder as it wont require you to edit this file.
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
Works for us, but my understanding may well be incorrect. Hope it helps
try this one which i think will solve your problem ..
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
you have to tell your server not to handle those directories over to index.php and the line which work for this is :
RewriteCond $1 !^(index\.php|robots\.txt|files\/images|files\/css|files\/js|files\/swf|files\/upload)
Here is my .htaccess file - which should work for you:
Options -Indexes
Options +FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
# activate URL rewriting
RewriteEngine on
# do not rewrite links to the documentation, assets and public files
RewriteCond $1 !^(files|css|js|swfimages|assets|uploads|captcha)
# do not rewrite for php files in the document root, robots.txt or the maintenance page
RewriteCond $1 !^([^\..]+\.php|robots\.txt|crossdomain\.xml|maintenance\.html)
# but rewrite everything else
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
thank you. this worked fine:
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I have another website and next index.php I have a folder called files, and this one content alot of folders should I have to put all names of them and names of sub-directories in them?
So, I've spend hours on this. I cannot figure it out. I've read several message boards and have not got it working.
Here's what I have done:
1)
Added a file called ".htaccess" to the folder "/www/site_name".
this file contains the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
2)
changed
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
3)
went through several httpd.conf files changing every possible combination of the lines:
AllowOverride None
to
AllowOverride All
4)
enabled the rewrite_module
This is driving me absolutely mad. I've spent literally hours on this.
EDIT:
Maybe i'm not setting the right AllowOverride to all. Which one is the right one?
EDIT:
I got it working. Thank you to the chosen answer for the help
Below is the .htaccess file which I use on my codeigniter installations. Perhaps you could try it out in an attempt to rule out the .htaccess file? If this works then we can add in your other rules if they're really necessary for your situation?
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?baseurl=$1 [QSA,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
The lines below bulk cater for your requirement to allow directories like /images/ and files such as robots.txt etc. If the file or folder exists it wont be rewritten. The application and system directories are protected by the other rules though.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d