I want to ask you guys, how to change subpages names? Like when I created my website first page is index.html (when I wrote it in taskbar and enter this website it shows www.example) next is gallery.html but when I go to gallery it show www.example/gallery.html and I want to be like this www.example/gallery without .html or even www.example/g. Thanks for helping me out!
Use this .htaccess code. Rewrites www.myweb.com/test.php to www.myweb.com/test
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^.*$ $0.php [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.+)\.php$ $1 [L,R=301,NE]
Related
I need to hide a folder from a url.
An example:
If I enter www.mysite.com/Jango
I need you to read the directory: www.mysite.com/users/Jango
but do not want to see /users
I just want to see this in the address bar:
www.mysite.com/Jango
This .htaccess in / should do:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^users/
RewriteRule ^(.*)$ users/$1 [L]
This treats any requset not starting with users/ as if it did.
Update:
If you want the rule to apply for only /Jango --> /users/Jango, this would be an appropriate .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^users/Jango
RewriteRule ^Jango/(.*)$ users/Jango/$1 [L]
(The [L]-flag stops rewriting afther this rule, preventing possible circle-reactions etc)
First question. So I have a simple website "website.com" on Apache:
website.com
index.html
site1.html
site2.html
Within each html I have links to other, in this form:
main
site1
site2
I want the browser to display "website.com/site1" instead of "website.com/site1.html".
I've been playing with it for a few days and I always end up with one of these results:
Infinite loop of redirects.
Internal server error.
Both versions work (eg. "website.com/site1.html" and "website.com/site1") but the .html stays in the address bar.
I don't know what's going on. I can't even break it properly. For example I expected that this .htaccess will throw an error on accessing "website.com/site1", because there is no rule redirecting site1 to site1.html:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [R=302,QSA]
But no - it works, just doesn't delete .html in the address bar.
How Apache knows to redirect "website.com/site1" to "website.com/site1.html" without the proper RewriteRule for it? Is my understanding wrong, that I have to redirect from website.com/site1 to website.com/site1.html to make it work?
Thanks in advance.
The last line at your rules :
RewriteRule ^(.*)\.html$ /$1 [R=302,QSA]
It means to change any file.html to file only and what you need is to accpet file only the redirect it internally to file.html like this :
RewriteRule ^(.*)$ /$1.html [L,QSA]
But , in this case , the file.html will be as is so, if you want to remove .html at all try the folowing rules :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*)\.html[\s?/] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /$1.html [L]
The first two lines after RewriteEngine on will remove .html .
The rest of lines will check whthere the request withut extention is .html file or not , if it is accpeted .html it will be redirected but internally .
Now , both , site1.html or site1 will be site1 in browser.
By this , you will make sure that file accepet .html extention before redirecting and that will seperate this stage of being mixed with error files.
I've been struggeling to get a .htaccess file to work correctly for a while now. What I basically want is to change the domain from e.g. www.domain.com/products/products.html to www.domain.com/products I've been trying for so long that I've started to consider it being unsupported by my hosting service (hostgator, and they don't know).
This is the code I scrambled together that only gives me the default missing page error.
RewriteEngine On
RewriteRule ^test?$ hidden/hidden.html [NC,L]
The structure:
Folder (hidden) -> Hidden.html
Index.html
.htaccess
I made some progress while my wait, I was able to get 3 links working however not the fourth one. That leaves me more confused the before.
My code currently looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^website\.com$
RewriteRule (.*) http://www.website.com/$1 [R=301,L]
RewriteRule ^$ index.html [L]
RewriteRule ^staff$ staffmembers/staffmembers.html [L]
RewriteRule ^donate$ idonate/idonate.html [L]
RewriteRule ^private$ hidden/hidden.html [L]
The only link that dosn't work is website.com/donate however every other links works fine at this point. Anyone that have a clue of why or a solution of how?
My aim is:
domain.com/folder
rewrite ->
domain.com
this shall concern ALL links inside that site.
I mean on the site are links like:
domain.com/folder/forum.html
domain.com/folder/community.html
etc.
This is my aim:
domain.com/forum.html
domain.com/community.html
etc.
and its very important that the "folder" is never in the url in the adressbar visible.
I tried already many codes but I couldnt really solve this problem.
My best try was with this code:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)folder
RewriteRule ^(.*)$ folder/$1 [L]
If I enter
domain.com
I get the content of
domain.com/folder
displayed, what is correct ("folder" is not in the url shown). But when i click on some links of the site like: domain.com/folder/community.html then I can see again "folder" in the url, but I want that it becomes ALWAYS removed.
here is my site:
thewedgiecommunity.x10.mx/wedgiecommunity/
My aim is to remove the "wedgiecommunity" (=folder)
This link is working
thewedgiecommunity.x10.mx/
But when you click on Community (
thewedgiecommunity.x10.mx/wedgiecommunity/community.html
) then i get again "wedgiecommunity" in the URL.
Would be awesome when someone could help me
You can use this code:
Goes in DOCUMENT_ROOT/wedgiecommunity/.htaccess:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+wedgiecommunity([^\s]*) [NC]
RewriteRule ^ %1 [R=301,L]
Goes in DOCUMENT_ROOT/.htaccess:
RewriteEngine On
RewriteRule !^/?wedgiecommunity wedgiecommunity%{REQUEST_URI} [L,NC]
You can use this rule to "remove" the folder from the URL when it is accessed directly via the browser:
RewriteCond %{THE_REQUEST} \ /wedgiecommunity/
RewriteRule ^wedgiecommunity/(.*)$ /$1 [L,R=301]
Then your other rule will handle the rest.
I use Dokuwiki for my website. I have a quick question about htaccess rewrite rules. I have the following configuration. The suggestions come from the Dokuwiki help.
Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^lib/exe/xmlrpc.php$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
RewriteRule ^_media/(.*) lib/exe/fetch.php?media=$1 [QSA,L]
RewriteRule ^_detail/(.*) lib/exe/detail.php?media=$1 [QSA,L]
RewriteRule ^_export/([^/]+)/(.*) doku.php?do=export_$1&id=$2 [QSA,L]
RewriteRule ^$ doku.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) doku.php?id=$1 [QSA,L]
RewriteRule ^index.php$ doku.php
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
I admit that I don't understand all of what's going on. The important thing is that I want
http://mydomain.com
to be changed to
http://www.mydomain.com
and also any subdomains. Also, I want to get rid of the ugly Dokuwiki syntax, which attaches things like doku.php? to the end of links.
Currently, the transformation with this .htaccess file is:
[Good] www.mydomain.com --> www.mydomain.com
[Good] www.mydomain.com/mypage --> www.mydomain.com/mypage
[Bad] mydomain.com --> www.mydomain.com/doku.php
[Bad] mydomain.com/mypage --> www.mydomain.com/doku.php?id=mypage
so you see, it seems to work properly if I attach www in front of things, but when I don't, then the re-write rule attaches the proper www, but now the ugly wiki syntax also accompanies the site name (doku.php and id= parts).
Where did I go wrong in the htaccess configuration?
TSGM, that looks fine except that you have the rewrite from mydomain.com to www.mydomain.com as the last two lines. Move the last two line up so that they are just after RewriteEngine on and that should fix it.
The reason being that (sometimes) a redirect was triggered to create the 'clean urls' and when this happened the rewrite to www never gets executed.
By moving the two lines up, you are forcing the www rewrite to happen first before the doku rewrite kicks in.