So I have a subfolder for my website, however, it still appears as www.domain.com/community/index.html.
I would like to remove the /index.html part.
I currently have this in my .htaccess file:
ErrorDocument 404 /404.html
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On
RewriteBase /
# redirect html pages to the root domain
RewriteRule ^index\.html$ / [NC,R,L]
I have a basic understanding of what this does, though, I am unsure on how to achieve this, so any help would be great!
This might not be the correct/best solution, however, I've created another .htaccess file within the sub directory, and that seems to work perfectly fine.
But if anyone has any better/correct solutions I'd still be happy to hear them.
Related
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.
I just want to make the GET information that I sent:
http://mywebsite.com/folder/index.php?category=category-alias-here
http://mywebsite.com/folder/index.php?category=category-alias-here&page=5
To be rewrited on the URL bar as:
http://mywebsite.com/folder/category-alias-here/
http://mywebsite.com/folder/category-alias-here/5/
And I cant. Its very simple, I saw several similar questions. Tested several examples on stackoverflow and they all give me 404 for both category and both pages.
Here is a code that I tested:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ index.php?category=$1&page=$2 [L]
I understand that this code be wrong for my structure specifically, I tried several changes placing and removing ([^/]+) or changed the fist [L] to [N]. And several other things. But no luck with that.
Please notice, the whole website is inside a real directory (/folder/) and the .htaccess is also there (its not on root), once I launch the website everything will be on public_html, but I do not think this is the reason of this issue.
And yes, mod_rewrite is on. There is actually a .htaccess that I use, it works anywhere I place and it gets the category correctly but it is a bit messy.
Found a solution:
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([a-z-]+)\/([0-9-]+)\/$ index.php?category=$1&page=$2 [NC,L]
RewriteRule ^([a-z0-9-]+)\/$ index.php?category=$1&page=$2 [NC,L]
I have a daunting problem with dynamic redirects that I have to do on WordPress website that was before an aspx website.
I am looking for advice for a week now and tried almost everything with different outcomes but none proved successful.
I need to redirect complex URLs such as:
/Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
to something simple like
http://domain.com/folder/
I've used number of ideas including loads from StackOverflow but none seem to tackle this specific example. Using standard Redirect 301 rule will work for as long as I don't have ? in the link. I understand this is beyond the scope of Redirect 301 and I need to use RewriteRule.
I tried this (got this from the excel spreadsheet for dynamic urls redirection):
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
But still on entering the url it yields 404 page.
Here's my .htaccess:
## 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]
## messing up
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://domain.com/folder/? [R=301,L]
</IfModule>
Do I place it correctly? Is the code right? I would appreciate any ideas and clues.
Thanks a million
I have solve the mastery. The code was good just the placing was incorrect. After dozen tries and errors I found the correct formula. I had to amend placing of my redirect rule. Here is how it looks:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default\.aspx$ http://doamin.com/folder/? [R=301,L]
RewriteCond %{QUERY_STRING} ^SortField=ProductName%2CProductName$Products/tabid/174/CategoryID/134/List/0/Level/a/ProductID/6572/Language/en-GB/Default.aspx?SortField=ProductName%2CProductName
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
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?
I don't have much experience with htaccess. But I have this script:
Options +FollowSymLinks
ErrorDocument 404 /index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*)$ index.php?doel_url=$1 [L,QSA]
But if there exists a file, he just listen to this rule.
Help!
website.nl/categorie is not a file and is not a directory.
if you need categorie to go to the file you will need to make sure it has a file extension (in your case .php) so it should be website.nl/categorie.php to avoid being redirected to the index.php page
Options -MultiViews should fix that.