I have a development version of a website that I want to hide/disable. But I don't want to delete the files for the moment. I also don't want to redirect requests to somewhere else. I just want to respond to the requests for that website with a HTTP 404.
How should I do it?
I am using Apache and .htaccess.
You could do something like this:
RewriteEngine on
RewriteRule ^oldsite/?$ http://www.domain.com/errorpage.html [r=301,nc]
This is a little gentler than a hard 404. Otherwise you can change the response code. Hope this helps.
Related
Search Console Error is showing me this URL:
/domain.com/.html as an error.
If I put that url in my browser I get:
Forbidden
You don't have permission to access /.html on this server.
this situation is because Apache is searching a file named .html how can I add a rule for htaccess file to fix this situation? if the URL is /.html redirect to index /
Good Morning,
why exactly do you want /.html to be a valid call? Shouldn't it be /specificName.html like /stack.html?
Anyway, try something like this:
RewriteRule /(specificName)\.html$ / [R=permanent,L]
If you really meant /.html just leave the bracket out.
Hope it helps :)
I have a shared hosting Apache server, and I'm trying to send visitors who come to the main domain URL to a specific page, with the URL replaced and a 303 redirect:
example.com
example.com/
to
example.com/subdirectory/page.html
Only the plain domain URL should get redirected, not:
example.com/page.html
example.com/otherdirectory
example.com/otherdirectory/
example.com/subdirectory
example.com/subdirectory/
example.com/subdirectory/otherpage.html
example.com/subdirectory/otherdirectory
example.com/subdirectory/otherdirectory/
example.com/subdirectory/otherdirectory/page.html
I'm not sure that RewriteEngine is allowed on this server, if there are alternative approaches possible.
The crude way I've thought of is to just use DirectoryIndex to send the visitor to example.com/index.php -- and have a PHP redirect in that file go where I want. But I'm not sure if this might produce a visible blip for some visitors, or how Google would feel about it.
I've found other instances of this kind of question on Stack Overflow, but the answers are failing for me in some way or another. As the behavior is not intuitive, testing before posting might be advisable.
Thanks
If mod_rewrite is not enabled you can use mod_alias based rule like this in your DocumentRoot/.htaccess:
RedirectMatch 303 ^/?$ /subdirectory/page.html
UPDATE: Equivalent mod_rewrite rule:
RewriteEngine On
RewriteRule ^/?$ /subdirectory/page.html [L,R=303]
Stackoverflow users,
I have an Apache application that needs to accept data POSTed to the following paths:
/sample/HostChange/Submit
/sample/HostChange/SubmittoAPI
I'm currently using the following 301 redirect rules. This is not what I want as as the POST gets redirected and the second request is a GET loosing all the data. I am seeing the 301 request go the correct url but the second request is a GET and causes a 405 response code.
.htaccess:
RewriteEngine On
Redirect 301 /sample/HostChange/Submit /event
Redirect 301 /sample/HostChange/SubmittoAPI /date
I'm sure using a Redirect is the issue. Can someone help me figure out the correct RewriteCondition I need to be using to redirect these POST hits to the new paths but keep the data being submitted to the application.
Thank you mucho.
I don't think you can redirect a POST (as a POST). Browsers just won't POST the data again.
You'd have to output some HTML with Javascript to make the browser rePOST the data to the new URL.
Or instead of redirecting, have some server-side code accept the POST data first and then dispatch it somehow (maybe be redirecting with an indentifying token in the URL) internally.
Or if the data is short, re-write the URL to include the data as query parameters.
Something along the lines of following should work, I'm not around an apache instance at the moment so regex is not tried but please check the rewrite log and see how it behaves.
RewriteEngine On
RewriteLog /var/log/httpd/rewrite.log
RewriteLogLevel 9
RewriteCond %{REQUEST_URI} /sample/HostChange/Submit
RewriteRule ^/sample/HostChange/Submit(.*) /event/$1 [P,L]
I some kind of the same problem, for me it helped not to really redirect the request, but to rewrite it. I don't now if this is applicable to your problem.
Here are the details and it worked for me:
PHP Rewrite url and preserve posted data
I have a problem.
The follow code is my Apache configuration:
RewriteRule ^/page-(.*)$ https://%{SERVER_NAME}:%{SERVER_PORT}/site/spaces/portal/page/$1 [QSA]
So, its OK. But, when I access my page like:
www.mysite.com/page-page?query=blah
It redirects the URL without the query=blah params.
What I'm doing wrong?
Thanks
I am not sure why they are missing, but you should be able to put them back with %{QUERY_STRING}.
I'm developing a webapp and for the static files I'm simply using apache at localhost while the backend is on a couchdb instance running at localhost:5984.
The webapp interacts with files from the backend all the time. So what is happening when trying to test on apache all file requests to localhost:5984 are getting blocked due the cross-domain policy so the only way to get that working is starting the browser by setting flags to ignore that.
But again I get stuck when trying to test the app on mobile such ipad or iphone.
Currently I have this on my .htaccess file.
RewriteEngine on
# these are 302 http redirections instead of serving as a proxy
RewriteRule auth http://localhost:5984/auth [L]
RewriteRule db/([\s\S]+) http://localhost:5984/db/$1 [L]
RewriteRule send/([\s\S]+) http://localhost:5984/send/$1 [L]
# these are just redirections to static files and work great
RewriteRule ^([a-z/.]+) _attachments/$1 [L]
RewriteRule ^$ _attachments/ [L]
As you can see I have really no idea on how to deal with apache configuration unfortunately.
But what is happening right now is that for some of these rules apache is simply redirecting the page instead of provide it as a proxy server which causes the issue with cross-domain.
Also on the first auth rule I send POST and DELETE requests which as a redirection instead of proxy it won't pass the data being POSTed through.
So what I would like to achieve is to activate some kind of feature (if it exists) which will make apache simply render the page as it was on the localhost domain instead of redirect it. (I named this a a proxy, but perhaps that's not even the right term, sorry for any mistake committed with the nomenclatures).
Is is possible to achieve such action?
Thanks in advance
Have a look at these links / options:
[P] flag:
http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
http://httpd.apache.org/docs/current/rewrite/proxy.html
mod_proxy (possibly -- but I think #1 should be enough if it's on the same server):
http://httpd.apache.org/docs/current/mod/mod_proxy.htm