I want to show a 503 error for a page on my website. (Using htacess) So far I've tried the following but it seems to be not working.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /league.php [R=503,L]
Is this correct? Or is there anyway to give the absolute URL path? Thanks.
Could you please try following, tested and written with shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/webmail/?$ [NC]
RewriteRule ^(.*)$ league.php [R=503,L]
OR using errordocument option.
ErrorDocument 503 /league.php
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/webmail/?$ [NC]
RewriteRule .* - [R=503,L]
Related
I've been looking for an answer for my problem, however the things I tried didnt work out. What I've been trying to do is to create a beatiful url for this link:
mywebsite.com/blog_template?slug_url=blog-post-name
to
mywebsite.com/blog-post-name
To achieve this I tried the following code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog_template/([^/]+)$ /blog_template?slug_url=$1 [L]
But my code didnt work... Any advice?
Here’s the full htaccess my website:
RewriteEngine On
RewriteBase /
ErrorDocument 404 http://91.218.67.117/404/
ErrorDocument 500 http://91.218.67.117/500/
#redirect 404
RewriteCond %{REQUEST_URI} ^/500/$
RewriteRule ^(.*)$ /pages/errors/500.php [L]
#remove php
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]
Considering you want to rewrite this request in backend to index.php(OR change it to appropriate file's name in case its some other php file). With your shown samples and attempts please try following .htaccess Rules.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /
RewriteCond %{THE_REQUEST} \s/blog_template\?slug_url=(\S+)\s [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/?$ index.php?slug_url=$1 [QSA,L]
ErrorDocument 500 /pages/errors/500.php
NOTE: Please keep your .htaccess file and index.php(OR any php file which is taking rewrite request in backend for that matter) in same path(your root etc).
Your attempt was close. Just a small fix:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/?$ /blog_template?slug_url=$1 [L]
This relies on additional rewriting rules to get applied though, since /blog_template most likely is not a resource the http server can somehow "execute" immediately. So you may want to combine above rule with other rules, which you did not reveal to us, which is why I cannot say anything about that.
If you also want to redirect requests to the "old" URL, then that variant should do:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^slug_url=([^/]+)$
RewriteRule ^/?blog_template$ / [QSD,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?([^/]+)/?$ /blog_template?slug_url=$1 [L]
It is a good idea to start out using a R=302 _temporary_redirection and to only change that to a R=301 permanent redirection once everything works as expected. That prevents nasty caching issues on the client side.
I want to convert this URL example.com/post.php?id=12345&title=xyz to example.com/12345/xyz.
I am able to do example.com/12345 but I can't get /xyz.
RewriteEngine On
RewriteRule ^post/([a-zA-Z0-9-/]+)$ post.php?id=$1
RewriteRule ^post/([a-zA-Z-0-9-]+)/ post.php?id=$1
With your shown samples, please try following htaccess Rules. Please make sure to clear your browser cache before testing your URLs.
This solution assumes that you are hitting example.com/post.php?id=12345&title=xyz sample url in browser and want to change it to example.com/12345/xyz
##Enabling engine here.
RewriteEngine ON
##Extrenal redirect 301 to mentioned url by OP in question.
RewriteCond %{THE_REQUEST} \s/post\.php\?id=([^&]*)&title=(\S+)\s [NC]
RewriteRule ^ %1/%2? [R=301,L]
##Internal rewrite to post.php with query strings.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/?$ post.php?id=$1&title=$2 [QSA,L]
I would like to ask for help.
I have this .htaccess file
The .htaccess file is used for redirect on example.com, when user enter another domain (which is also directed to this hosting). And then there are rules for "pretty URL addresses":
example.com/advert/xx leads to example.com/advert.php?id=xx
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^advert/([^/]+)/?$ advert.php?id=$1 [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^adverts/([^/]+)/?$ adverts.php?kat=$1 [L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^adverts/([^/]+)/([^/]+)/?$ adverts.php?kat=$1&podkat=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
ErrorDocument 404 /404.php
The problem is, that it causes errors like this:
client denied by server configuration:
/data/web/virtuals/56654/virtual/www/advert
I think the server is looking into FOLDER advert which does not exist (it's only the pretty URL rule).
The support from hosting told me that my .htaccess file is wrong.
Could someone please tell me where am I wrong?
Thanks everyone for help.
Your first RewriteCond starts with **. Remove those or in case you want to comment out some lines, start those lines with a #. Same for your first RewriteRule at the end of the line.
I had the same issue, and having the RewriteRule include the DocumentRoot in the path resolved it for me.
This got denied:
RewriteRule ^/webapp/([\w]+) /script.cgi?id=$1
This worked:
RewriteRule ^/webapp/([\w]+) /var/www/html/script.cgi?id=$1
I do have directory permissions in my httpd.conf. This may not be an issue if you're not using directory permissions.
I am using this rewrite rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST} ^img.domain.com [NC]
RewriteRule ^(.*)$ data/photos/$1 [L]
Its doing that, when I use f.e http://img.domain.com/profile_image.jpg it will show content of file http://www.domain.com/data/photos/profile_image.jpg without changing url (masked). This is ok.
The problem is, just in case, when somebody enter http://img.domain.com, it will return 500 Internal server error, but I want it to show 403 Forbidden, the same as when you enter http://www.domain.com/data/photos/. I am helpless, how to modify this rewrite rule to achieve this?
EDITED:
Also the same issue is when the file doesnt exist in /data/photos/, then I want to return 404... but its returning 500.
In errorlog is too many recursions...
You should first check whether destination file exists and then rewrite it:
# 403 for img subdomain when request is for landing page
RewriteCond %{HTTP_HOST} ^img\.domain\.com$ [NC]
RewriteRule ^(data/photos)?/?$ - [F,NC]
RewriteCond %{HTTP_HOST} ^img\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/data/photos/$1 -f
RewriteRule ^(.+)$ data/photos/$1 [L]
I have modified .htaccess to remove trailing .html from my pages. htaccess looks like this:
RewriteEngine on
RewriteBase /
RewriteCond %{http://www.mydomain.co.uk} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://www.mydomain.co.uk/$1 [R=301,L]
I also added the following at the top of the .htaccess to set up a custom 404 page and stop indexing:
ErrorDocument 404 /notfound.html
Options -Indexes
The rewrite rule works perfectly. So does the anti-indexing. However the 404 page gives me this error:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster#mydomain.co.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
If I remove the rewriterule then the 404 page works fine. I don't know a lot about this kind of stuff and was wondering what to do to be able to get both aspects to work correctly? Can anyone help please?
(PS: I read this answer and think it might apply to me - but didn't understand it at all.)
Just wanted to let you know I found a solution for this:
ErrorDocument 404 /notfound.html
Options -Indexes
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/\ ]+/)*[^.\ ]+\.htm\ HTTP/
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(([^/]+/)*[^.]+)\.htm$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://www.example.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(([^/]+/)*[^./]+)$ /$1.html [L]
Works great!