Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
According to WikipediaA .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration. They are placed inside the web tree, and are able to override a subset of the server's global configuration for the directory that they are in, and all sub-directoriesFromOracle-Docs:If you enable .htaccess files, the server checks for .htaccess files before serving resources. The server looks for .htaccess files in the same directory as the resource and in that directory's parent directories, up to and including the document root.For example,if the Primary Document Directory is set to/oracle/server/docsand aclient requests/oracle/server/docs/reports/index.html,the server will check for :.htaccessfiles at/oracle/server/docs/reports/.htaccess and /oracle/server/docs/.htaccess.suppose you have 2 sites and you want to setup.htaccessfor both your both sites using a single filethen just create the file structure like followingparentsite1site2.htaccessHereupload all data of site1into thesite1 folderand so on.
So I am creating a template system that is the same across multiple sites, the only thing that changed is the configuration file. I am making so all the files are getting fetched from the root directory. I can do it with all my php and html files, but I can't see to figure it out on my .htaccess file. How the directory is set up is /home/user_name/template and then there are also folders like /home/user_name/site1.com and all off the sites. So how can I make all of the site use the same .htaccess file. I hope that makes sense!
Load .htaccess From Root Directory
Try this - you want to match example.com (remove the !), and it's clearer to capture the incoming url into $1.RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com$ RewriteRule ^(.*)$ http://example.de/$1 [L,QSA,R=301]Also, while debugging, change theR=301toR, so your browser doesn't "stick" with an old rule. When it works, change it back toR=301
I have a website with 2 different domains, for example:www.example.com www.example.netNow i want, that every user coming fromexample.comshould be redirected towww.example.deIll tried:RewriteEngine On RewriteCond %{HTTP_HOST} !^example\.com$ RewriteRule ^.*$ http://example.de/$0 [L,QSA,R=301]But now still all users fromexample.netget redirected toexample.deHow can i solve that, that only users fromexample.comgets redirected (also with all subfolders).Thanks!
Redirect only with specific domain
I came across this because I had the same problem.Just in case anyone else finds this, I found the perfect solution:Beginning in Apache 2.4.19, you can use the parameter "Require forward-dns [hostname]", which simply allows all IPs behind [hostname].https://httpd.apache.org/docs/2.4/mod/mod_authz_host.html#requiredirectives
On my Authentication page i have it only allow from certain IPs. Is it possible to have it allow by a domain name? The IP of my home network is dynamic but the domain name (mysite.com) always points to the correct IP address.
htaccess: Allow from domain name instead of IP/subnet
You can add this code to your htaccess file (which has to be in root folder)RewriteEngine On RewriteRule ^sitemap\.xml$ /index.php?eID=dd_googlesitemap [L]Make suremod_rewriteis enabled
I have a content management system plugin installed that provides a sitemap for Google underhttp://www.domain.com/index.php?eID=dd_googlesitemaphow can I add a rewrite rule to my .htaccess that will make this sitemap available underhttp://www.domain.com/sitemap.xmlinstead?
Rewrite rule .htaccess for my sitemap.xml
Precedence is everything!If you allow localhost to connect, and afterwards deny ALL ips, the deny overwrites the allow.So you'd first apply the blacklist (deny all) and then the whitelist (allow localhost).Order deny,allow # <--- order to apply the white/blacklist change Allow from 127.0.0.1 Allow from ::1 Deny from allhttp://httpd.apache.org/docs/2.2/howto/access.htmlThe Order directive goes hand-in-hand with these two, and tells Apache in which order to apply the filters.
I am using XAMPP on windows 7. I put this htaccess file in myhtdocsfolder and I'm getting access denied when I try to openhttp://localhost/.Order allow,deny Allow from 127.0.0.1 Allow from ::1 Deny from allI want to deny access to any computers other than this one. How can I do this?
htaccess allow from 127.0.0.1 not working
Use this rule in yourRetailer/.htaccessfile:RewriteEngine on RewriteBase /Retailer/ RewriteRule ^((?!public/).*)$ public/$1 [L,NC]
I have scratching my head over it for a long time now. Can't manage to get it to work. (I am a noob with apache that can be one reason also). Ok here is the problem in nutshell. I am using wamp and I have a directoryRetailer. There is another directory inside it which is called public that contains the index and otherfiles. I want to make thispublicdirectory document root. I want to achieve this with.htaccessMy Rewrite module for apache is turned on.Here is what I have tried:RewriteEngine on RewriteBase /public/ RewriteRule ^index.php$ test.phpAnd also I have triedRewriteEngine on RewriteCond %{HTTP_HOST} ^localhost/Retailer$ [NC,OR] RewriteCond %{HTTP_HOST} ^localhost/Retailer$ RewriteCond %{REQUEST_URI} !public/ RewriteRule (.*) /public/$1 [L]And I have triedRewriteEngine on RewriteCond %{HTTP_HOST} ^http://localhost/Retailer/$ [NC,OR] RewriteCond %{HTTP_HOST} ^http://localhost/Retailer/$ RewriteCond %{REQUEST_URI} !public/ RewriteRule (.*) /public/$1 [L]But result in all these cases is the same. That is:Any help will be appreciated Ahmar
Change document root using .htaccess on wamp
Try:RewriteEngine On # for subdomains RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC] RewriteCond %{HTTP_HOST} ^(?:www\.|)(.*)$ [NC] RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L] # for main domains RewriteCond %{HTTPS} !=on [OR] RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] RewriteRule ^.*$ https://www.domain.com%{REQUEST_URI} [R,L]
I've been trying to configure this for my website, but not being able to.I use to have a cond on my .htaccess to force www for the main domain and nothing for subdomains, but since I got a SSL, I'm having some problems.It's a wildcard SSL.What I need is force HTTPS:// WWW on the main domain, and HTTPS:// on subdomains.I.E:http://www.domain.com->https://subdomain.domain.comIs there any rule for that? Thanks!EDITEDNow I'm using like Jon postedRewriteEngine On RewriteCond %{HTTPS} !=on [OR] RewriteCond %{HTTP_HOST} ^domain\.com\.br$ [NC] RewriteRule ^.*$ https://www.domain.com.br%{REQUEST_URI} [R,L] # ---------- # RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com\.br$ [NC] RewriteCond %{HTTP_HOST} ^(?:www\.|)(.*)$ [NC] RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]The thing is, when on main domain if I type HTTP:// with or without WWW, ir forces HTTPS:// and WWW, that's ok...But on subdomain, when I type HTTP it doesn't force HTTPS, it redirects to the main domain only... that does not happen if I put a .htaccess inside the dir of the subdomain. With a .htaccess inside my subdomain dir, if I type HTTP, it forces HTTPS normally...Any suggestions?
Force HTTPS and WWW for domain and only HTTPS for subdomains HTACESS
The[R=301]will let mod_rewrite know the request should be redirected, but the request will not be redirected instantly. It will evaluate rules until it finds the[L]or[END]flag (or it hits the end of the file). It now matches the first rule, and tell that when mod_rewrite feels ready, it should redirect. mod_rewrite still hasn't found anLorENDflag yet and still has rules to match. It then will match the second rule and include that in the redirect.You need to change the flags for the first rule to[R=301,L]to make it redirect. The redirected request will invoke this.htaccessagain and the second rule will be matched if needed. It then will work properly as an internal rewrite again.
I am using followinghtaccessRewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301] RewriteRule ^user/([^/]*)/$ /user/index.php?usr=$1The First three lines redirects non www url to www for my website..The other line redirects for canonical purpose e.g.www.mysite.com/user/index.php?usr=JAHAJEEwill becomewww.mysite.com/user/JAHAJEE/.My problem is after i have added the above redirect for non www to www, the canonical redirected pages show the url parameter (e.g.www.mysite.com/user/JAHAJEE/?usr=JAHAJEE) . Please checkhttp://www.jahajee.com/user/JAHAJEE/&http://jahajee.com/user/JAHAJEE/How can I prevent url parameters to be shown in the redirected URL. Thankyou in advance.
Querystring of internal rewrite shows up in redirect
For CI, you want something like your first set of rules, but without the redirect. But the redirect needs to happen before the routing happes, so try:RewriteEngine On # redirect www to non-www RewriteCond %{HTTP_HOST} ^www\.base\.com$ [NC] RewriteRule ^(.*)$ http://base.com/$1 [L,R=301] # redirect direct requests to /index.php to remove it RewriteCond %{THE_REQUEST} \ /index\.php/?([^\?\ ]*) RewriteRule ^ http://base.com/%1 [L,R=301] # internally route to /index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [PT,L]
I am using CodeIgnter, as for a result all my links are likebase.com/index.php/home/indexorwww.base.com/index.php/home/index. I would like to display them only asbase.com/home/indexif possible.I have tried looking over the internet,got the rewrite in htacces from both of them as:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$0 [PT,L] RewriteCond %{HTTP_HOST} ^domain\.com\$ [OR] RewriteCond %{HTTP_HOST} ^www\.domain\.com\$ RewriteRule ^/?$ "http\:\/\/domain\.com\/" [R=301,L]andRewriteEngine on RewriteCond %{HTTP_HOST} !^domain\.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]put them separately,they work.But toghether they don't do what i need them to do. Anyone knowing the solution?Thanks.
rewriting www to non-www and index.php CI
Flags you mentions are related to mod_rewrite, butRedirectis part of mod_alias and has different syntax.See here:https://httpd.apache.org/docs/current/mod/mod_alias.html#redirect
Can I use theRedirect 301with Flags like NC and L?For example:Redirect 301 /test.htm /example/test/ [NC, L]I'm getting server errors but I'm not sure if it's because Redirect 301 doesn't allow flags at the end of the statement or if it's something else.
Redirect 301 With Flags
- CreateErrorDocumentdirective like this:ErrorDocument 404 /404.php2 - Then create your404.phplike this:<?php if ($_SERVER["HTTP_HOST"] == "domain.com") // current domain header('Location: http://example.com' . $_SERVER["REQUEST_URI"], TRUE, 301); ?>UPDATE Using just .htaccess:RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]
How can I redirect all the 404 errors to another domain?I've found theError 404 http://example.com/error.htmlBut I need:if Error 404 (.*) http://example.com/$1I've tried:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ http://example.com/$1But it redirects all the requests, in fact if I run a .php script which generate a page with some 404 links the URL of the script becomeshttp://example.com/script.phpInstead the URL should remains the same and just the 404 links should get redirected to the other domain.Solutions?
.htaccess, rewrite 404 errors to other domain
I found the answer myself, certainly worked for what I needed:ErrorDocument 503 "<!DOCTYPE html><html><head><title>This website is undergoing maintenance</title></head><body style='font-family: sans-serif'><h1>This website is undergoing maintenance</h1></body></html>" RewriteEngine On RewriteRule .* - [R=503,L]Hope this helps somebody
Apologies if this is a stupid question, but can I control the HTML response from a .htaccess file (Apache)?In other words something like (psuedo code)Write <!DOCTYPE html><html>...[etc]The reason I ask is because I would like to "take down" some sites in one "hit", but without replacing any files or having any other kind of holding page.
Can I write an HTML response from an .htaccess file
Matching the entire query string and appending it to your new URL using a back-reference should work.RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{QUERY_STRING} ^(.*)$ RewriteRule ^(.*)$ $1.php?%1 [NC,L,QSA]
Here is my .htaccess file right now.RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ $1.php [NC,L,QSA]This works in the fact that it makes my pages accessible when not using the .php extension.Old = domain.com/test.php New = domain.com/testThe bad thing is that when I send get data with the following link the data is not passed. I thought the QSA option did that, whats the deal?domain.com/test?id=1
htaccess remove .php and keep query string
Write header like:header("Location: http://www.testing.com");on the home page ofhttp://www.testing.com/newsitefor more aboutheader
This question already has answers here:How do I make a redirect in PHP?(34 answers)Closed10 years ago.My site url iswww.testing.comand there is another sitewww.testing.com/newsite.I want everyone who hitswww.testing.com/newsiteto be redirected towww.newsite.com
How to redirect to a different URL [duplicate]
Change the www to check for the actual domain:#Force www. RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^domain\.com$ [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]Or, if you're hosting a bunch of domains, you can check for a name before the TLD:RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^([^.]+)\.([a-z]{2,4})$ [NC] RewriteRule ^ http://www.%1.%2%{REQUEST_URI} [L,R=301]As for the trailing slash, you have to be careful that the request isn't made for a directory. Because if it is, and you haveDirectorySlashturned on (by default it is on), then you'll cause a redirect loop.To exclude subdomains, we assume that the first rule redirected the browser to ensure that it started with "www", and since subdomains aren't being redirected to start with "www", we can just check for that:#Remove trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule ^(.+)/$ /$1 [R=301,L]
Here's what I have so far:#Force www. RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] #Remove trailing slash RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} (.*)$ RewriteRule ^(.+)/$ http://www.domain.com/$1 [R=301,L]However, this messes up all subdomains doing the following redirect:sub.domain.com -> www.sub.domain.comAnd also, its dependant on the domain written on the remove trailing slash bit.So... two questions.How do I rewrite the rule on the "remove trailing slash" bit to exclude writing the domain on it?How do I make a rewritecond to exclude subdomains, without explicitly writing them down, on the "force www." bit?Examples of desired results -sub.domain.com/something/ -> sub.domain.com/something domain.com/something/ -> www.domain.com/something www.domain.com/ -> www.domain.com sub.domain.com -> sub.domain.comThanks!
.htaccess force "www." on everything but subdomains and remove trailing slashes
### all your redirects # for www.example.com/index.php?page=homepage&paging=1 RewriteCond %{THE_REQUEST} \?page=([^&]+)&paging=([0-9]+) RewriteRule ^ /%1/%2? [L,R=301] # for www.example.com/index.php?page=gallery&topic=nametopic RewriteCond %{THE_REQUEST} \?page=([^&]+)&topic=([^&\ ]+) RewriteRule ^ /%1/%2? [L,R=301] # for www.example.com/index.php?page=namepage RewriteCond %{THE_REQUEST} \?page=([^&\ ]+)($|\ ) RewriteRule ^ /%1? [L,R=301] # for www.example.com/namepage/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)/$ /$1 [L,R=301] ### all your rewrites back RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([0-9]+)$ /index.php?page=$1&paging=$2 [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)$ /index.php?page=$1&topic=$2 [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)$ /index.php?page=$1 [L]
Can anybody please help me with some URL rewriting?I had: (EXAMPLES)www.example.com/index.php?page=namepage www.example.com/index.php?page=gallery&topic=nametopic www.example.com/index.php?page=homepage&paging=1I would like to have:www.example.com/namepage www.example.com/gallery/nametopic www.example.com/homepage/1I have in my htaccess file:RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/?$ ?page=$1 [L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)?/?$ ?page=$1&topic=$2But it doesnt work very well, because i can write:www.example.com/index.php?page=namepage (page or whatever)www.example.com/?page=namepage (page or whatever)www.example.com/namepage/www.example.com/namepage (THIS I WANT - no others)And second problem is:www.example.com/namepage (OK, i want, we see namepage)www.example.com/namepage/whatever (NO OK, i want 404, but we see namepage)www.example.com/gallery/topic (OK, i want, we see nametopic)www.example.com/whatever/whatever2/whatever3 (OK, i want 404)VERY THANKS TO ANYBODY.
.htaccess friendly URl
In the port 80 VirtualHost, a rule will rewrite everything that isn't the blog to SSL. In the 443 host, it will rewrite blog requests to non-ssl (if you want to force them back to non-ssl)<VirtualHost IPADDRESS:80> RewriteEngine On # Rewrite everything except the blog to SSL RewriteCond %{REQUEST_URI} !^/blog RewriteRule (.*) https://www.example.com/$1 [L,R,QSA] </VirtualHost> <VirtualHost IPADDRESS:443> RewriteEngine On # Rewrite the blog back to plain http # Leave this out if you don't care that https requests to the blog stay # on ssl RewriteRule ^(blog*) http://www.example.com/$1 [L,R,QSA] </VirtualHost>
I have two virtual hosts in httpd.conf one for port 443 and one for port 80:<VirtualHost IPADDRESS:80> </VirtualHost> <VirtualHost IPADDRESS:443> </VirtualHost>Now I want to redirect every request to my server to go tohttps://www.mysite.com/except forhttp://www.mysite.com/blog/I want the blog to be non SSL. Where should I put RewriteRules, in which of the virtualHost directives? And what kind of rule do I need for that?
Rewrite rule for httpd.conf and virtual host SSL
There is a LOT more going on to prevent hotlinking of images, than an .htaccess rule. However, the basis of what you'd want in your htaccess to prevent image hotlinking is :RewriteCond %{HTTP_REFERER} !^http://(www\.)?example.com/.*$ [NC] RewriteRule .*\.(jpg|jpeg|png|bmp)$ - [F,NC]Apache ReWrite guide
I'm using Apache and lets say there is a file at "images/sample.jpg".With.htaccess, how can i make itappearingon the website andthen preventthe direct access by url (for example, direct url like "http://www.abc.com/images/sample.jpg") ?If possible, i also want the solution to affect on all sub-folders below the ".htaccess" file.Additional Note:After one day of getting below answers, i found all solutions logically work, but problem with Firefox. I mean, the below answers are giving the solution while testing on every browser but not with Firefox.
(htaccess) How to make a file only accessable by host Server and prevent direct access?
You can try the following in your .htaccess file#modify query string condition here to suit your needs RewriteCond %{QUERY_STRING} (^|&)m=_\! [NC] #set env var MY_SET-HEADER to 1 RewriteRule .* - [E=MY_SET_HEADER:1] #if MY_SET_HEADER is present then set header Header set X-Robots-Tag "noindex, nofollow" env=MY_SET_HEADER
Is it possible to apply HTTP header directives based on the URL's query string using an apache .htaccess?For example, based on this resourcehttp://code.google.com/web/controlcrawlindex/docs/robots_meta_tag.htmlunder the section titled "Practical implementation of X-Robots-Tag with Apache" it says the following .htaccess file directive can be used:<Files ~ "\.pdf$"> Header set X-Robots-Tag "noindex, nofollow" </Files>I'm looking for something along the lines of:<QueryString ~ "m=_!"> Header set X-Robots-Tag "noindex, nofollow" </QueryString>This way the following URL would NOT get indexed by search engines:http://domain.com/?m=_!ajax_html_snippetAny hints/tips/clues would be much appreciated. Thanks.
How to set the X-Robots-Tag HTTP header via .htaccess file based on URL query string
Final solutionRewriteRule ^dictionary/([^/.]+)$ /words.php?q=$1 [QSA,L]
My htaccess rewrite must handle these scenarios:http://example.com/words/pantalónhttp://example.com/words/pantal%C3%B3nhttp://example.com/words/señor+señoraMy current .htaccess configuration is:RewriteRule ^dictionary/([\w\+]{2,50})$ /words.php?q=$1 [QSA,L]It is not recognizing the special chars, e.g.: ñ, ó.Any ideas? Thanks!
Htaccess RewriteRule to accept special characters
You don't need to name the fileindex.htmlto have it served by default. You can change the default document using your with an entry in your.htaccessfile like this:DirectoryIndex index.phpThen when you navigate tohttp://yoursubdomain.example.comyou will be servedindex.phpinstead ofindex.html.If really do want PHP to interpret your .html documents then the entry you had in your question will work when PHP is running as an Apache module. If your host is running PHP as CGI, you want:AddHandler application/x-httpd-php .htmlIf it still doesn't work, then this web page has some more suggestions:http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/
I would really like my index.html to be able to have a PHP script work on it. I read that you can do this through the htaccess file. I only have access to a subdomain website directory, where I can upload my files through FTP.The directory did not have a htaccess file, so I created one using notepad: .htaccess and added this to the file:AddType application/x-httpd-php .htmlThe problem is, instead of loading the index.html page, it downloads it as a file...would I need to add something extra to the htaccess file? :S
htaccess downloading file instead of loading
An easy way is to useredirectRedirect 301 /experiment.html /experiments.html
For example, if I have example.com/experiments.html and the user types in example.com/experiment.html (no "s"), is it possible to redirect the user to example.com/experiments.html using .htaccess?Edit: "experiments.html" was just an example, I have a lot of pages that users may type incorrectly. Is there an universal solution?
Fixing typos using .htaccess?
Use this:<Files ~ "\.(tpl|txt)$"> Order deny,allow Deny from all SetEnvIfNoCase User-Agent "Googlebot" goodbot Allow from env=goodbot </Files>
In my .htaccess file I have:<Files ~ "\.(tpl|txt)$"> Order deny,allow Deny from all </Files>This denies any text file from being read, but the Google search engine gives me the following error:robots.txt Status http://mysite/robots.txt 18 minutes ago 302 (Moved temporarily)How can I modify .htaccess to permit Google to read robots.txt while prohibiting everyone else from accessing text files?
robots.txt htaccess block google
I was getting the same Chrome error because my doctype was DOCTYPE! instead of !DOCTYPE. Chrome is probably being stricter somehow in parsing your HTML than other browsers; try pasting your code intohttp://validator.w3.org. Or maybe try the following line alone in your .htaccess file.AddType text/cache-manifest appcache manifestFor ease of testing refresh chrome://appcache-internals whenever you refreshhttp://www.matthewlehner.ca
I'm trying to set up a cache manifest for a site and am having little luck. A demo page is here:http://www.matthewlehner.caThe HTML I'm using has this structure:<!DOCTYPE html> <html manifest="manifest.appcache"> </html>.htaccess in the root folder has the following entry:AddType text/cache-manifest appcache AddType text/cache-manifest .appcacheResponse from `curl -Ihttp://www.matthewlehner.ca/manifest.appcache'HTTP/1.1 200 OK Date: Sun, 11 Sep 2011 00:04:30 GMT Server: Apache Last-Modified: Sat, 10 Sep 2011 07:53:30 GMT ETag: "18a84003-32-4ac9196f95280" Accept-Ranges: bytes Content-Length: 50 Content-Type: text/cache-manifestBut Chrome dev on OS X 10.6 is reporting the following error:Application Cache Error event: Invalid manifest mime type (text/plain) http://www.matthewlehner.ca/manifest.appcacheClearly this is not the case, but how do I fix this? Is it a Chrome, .htaccess, or hosting issue?
Chrome reporting html5 cache manifest mime type incorrectly
This should resolve your problem:RewriteEngine on RewriteCond %{HTTP_HOST} ^www.domain.com$ [OR] RewriteCond %{HTTP_HOST} ^domain.com$ RewriteRule ^(.*)$ http://www.thenewdomain.net$1 [R=301,L]
I need to redirect a URL domain.com to domain.net in a Rewrite rule. I originally used redirect, but it lost the POST variables I was sending. Will a Rewrite carry them over and what is the best way to do this?
How do I replace the domain name in a Apache Rewrite rule?
RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} protected [NC,OR] RewriteCond %{REQUEST_URI} protected2 [NC,OR] RewriteCond %{REQUEST_URI} protected3 [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !protected [NC] RewriteCond %{REQUEST_URI} !protected2 [NC] RewriteCond %{REQUEST_URI} !protected3 [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]you can useORto add more options!Here is more detail on mod_rewrite conditions:http://httpd.apache.org/docs/current/mod/mod_rewrite.html#RewriteCond
I have the following:RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} protected [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} !protected [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]If the directory is called "protected", make sure that the user is using https. If the directory is anything except "protected", make sure the user is using http.This works great, but how do I specify additional directories?Also, is there a way this can be accomplished without having to specify directories twice? One time for including it and one time for excluding it?Thanks!UPDATEAlthough my "protected" folder was forced to use https due to my rules, any references to images, stylesheets, and javascripts that were not in the "protected" folder were still being redirected to http. This causes the "protected" page to only be partially secure. Adding the following prior to the redirect code solves this:RewriteRule \.(css|gif|jpe?g|js|png|swf)$ - [L]
htaccess: force http on all pages and https on select directories
The following rewrite rules will redirect any request to cdn.example.com to example.com:RewriteEngine On RewriteCond %{HTTP:Host} =cdn.example.com RewriteRule (.*) http://example.com/$1 [R=301,L,QSA]
I'm not quite sure how to prevent google from indexing my CDN domain in mix with my Primary domain name. I would like to redirect to Primary domain via .htaccess on dirrect access to CDN domain.Facts:Both domains point to the same place in file sistem.Both share same robots.txtCDN domain: cdn.example.comPrimary domain: example.comThanks.
Redirect from CDN to Primary website on direct access of CDN domain?
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}This should do it.
This question already has answers here:How to redirect all HTTP requests to HTTPS using .htaccess rules?(29 answers)Closed10 years ago.I have a folder with images, which should be accessed only using HTTPS. How to redirect all requests from HTTP to HTTPS?
Force HTTPS request using .htaccess [duplicate]
lighttpd doesn't support.htaccessfiles like Apache httpd does. That's where the "light" in "lighttpd" comes into play.You can, however, migrate these rules from Apache httpd'smod_rewriteto lighttpd'smod_rewrite. But be aware that theNCflag (case-insensitive matching) isnotsupported by lighttpd's mod_rewrite. If you are fine without it, you could simply use the following rewrite rules:url.rewrite-once = ( "^packed\.js$" => "pack.php?debug=0", "^debug$" => "pack.php?debug=1" )If you need the match to be case-insensitive, you'll probably need to invokemod_magnetand a custom Lua script.
RewriteEngine on RewriteRule ^packed\.js$ pack.php?debug=0 [nc] RewriteRule ^debug$ pack.php?debug=1 [nc]That worked fine on apache in a .htaccess file placed in a specific directory. If I want to do this on lighttpd, do I have to add it in the config file or something?Would I need to make any changes to these rules?
apache .htaccess file on lighttpd
Using constants such asE_WARNINGhas no meaning outside of PHP -- and when you're writting a.htaccessfile, you are "outside of PHP".(see thedocumentation oferror_reporting, for instance)So, you cannot use those constants, and have to use their integer values, which you can find here :Predefined ConstantsThe easiest way to know which value you should use, in your specific case, is to use a small PHP script to do the calculation.For instance :<?php var_dump(E_ALL & ~E_NOTICE);Will output :int 30711(Much easiser than going through the constants' values, and calculating yourself I suppose ^^ )
I'm editing the .htaccess file in order to make some overwrites to my php.ini file (I don't have access to it). So far, I've added:php_value max_execution_time 600 php_value error_reporting E_WARNING php_value log_errors OffThe application I'm editing for (vTiger CRM) recommends that "error_reporting" is set to "E_WARNING & ~E_NOTICE". When I put in that value I end up with a Error 500. How can I add the proper error_reporting values? Thanks.
How Do I Enter Multiple PHP Values in .htaccess?
With mod_rewrite you can only change some specific header fields but to which theContent-Dispositionheader field doesn’t belong. You could only change theContent-Typeheader field:RewriteRule ^media/[^/]+\.mp3$ - [L,T=audio/mpeg] RewriteRule ^media/download/[^/]+$ - [L,T=application/octet-stream]And if you want to use amod_headers+mod_setenvifsolution:SetEnvIf Request_URI ^/media/download/ force-download <IfDefine force-download> Header set Content-Disposition attachment Header set Content-Type application/octet-stream </IfDefine>
I have a directory of mp3 files want to have be able to serve them inline or giving the user an option to download based on the request URI./media/file1.mp3 -- in this case, I just want to serve the file and let the browser play it./media/download/file1.mp3 -- in this case, I want to make it easy for a user to download the file instead.I have been able to accomplish this with mod_rewrite and php (using the header() and readfile() function) but I would rather do it all with mod_rewrite, mod_header etc if possible.
mod_rewrite help to change Content-disposition based on URI
Yes, you have an error. You forgot a ";" before script-src:Header always set Content-Security-Policy "default-src 'self'; script-src: 'self' 'unsafe-inline';"
Chrome is returning this error on the console while defining basic csp codes:The Content-Security-Policy directive name 'Content-Security-Policy:' contains one or more invalid characters. Only ASCII alphanumeric characters or dashes '-' are allowed in directive names.This is all I have on my .htaccess file:Header always set Content-Security-Policy "default-src 'self' script-src: 'self' 'unsafe-inline';"Is there anything wrong you can see? Thanks
Content Security Policy invalid characters
With your shown samples, please try following htaccess rules file.Please make sure to clear your browser cache before testing your URLs.RewriteEngine ON RewriteBase / RewriteCond %{ENV:REDIRECT_STATUS} ^$ ##using THE_REQUEST variable for condition check. RewriteCond %{THE_REQUEST} \s/([^.]*)\.php/?\s [NC] ##Performing external redirect here. RewriteRule ^ %1? [R=301,L] ##Performing rewrite for non-existing pages. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^(.*)/?$ /$1.php [QSA,L]
I tried a lot of code to remove.phpfrom urlfor example -ht.abuena.net/presto.php->ht.abuena.net/prestoand vice versa - internallyRewriteEngine ON RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L]nothing works - the url stays unchangedpage is reloading by right clicking on the buttonReloadand choosing -Empty Cache and Hard Reload- so I hope the cache is clearedlive example here -here
htaccess - remove .php extension from url
The problem is, you installed it in/codeigniter3/This should fix it:// remove index.php $config['index_page'] = "" // Allow installation in a subfolder of your webroot $config['uri_protocol'] = "REQUEST_URI"And keep your rewrite settings, they are ok.
I try to remove the index page in Codeigniterthe first step I do this //old Code$config['index_page'] = "index.php”//New updated code(Only Need to remove index.php )$config['index_page'] = ""then for second step i do this creat file .htaccess in root of codigniter then put this code sourceRewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]but it's the same problem and I can't refresh the web pagewith index page the URL work:http://localhost:8089/codeigniter3/index.php/Hello/dispdatabut without index page don't workhttp://localhost:8089/codeigniter3/Hello/dispdataHello is the controller, finally thank for help, :)
How to Remove index.php in URL
Your loaded modules imply Apache 2.4 where you have access to<If>and conditional expressions onHeader<If "%{HTTP_REFERER} =~ /www.external.domain/ && %{REQUEST_URI} == '/choose-language'"> Header add Set-Cookie country= </If>orHeader add Set-Cookie country= "expr=%{HTTP_REFERER} =~ /www.external.domain/ && %{REQUEST_URI} == '/choose-language'"
Is it possible to delete aspecific cookievia Apache if acertain pagerequest contains aspecific referrer?I have found a similar question which is about deleting cookies in general (How to remove a cookie in Apache) but this does not use any conditions or cookie names.My concrete use case is: Delete (or unset it's value) cookie named "country" if requested url is "/choose-language" and referrer is "www.external.domain".Currently the following Apache modules are available:core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_expires mod_filter mod_headers mod_mime prefork mod_negotiation mod_php7 mod_proxy mod_proxy_fcgi mod_remoteip mod_rewrite mod_setenvif mod_socache_shmcb mod_ssl mod_status
Delete cookie based on url and referrer
Change folder nameCodeIgniter-3.1.6tociSet yourbase_urlto$config['base_url'] = 'http://localhost/ci/Use this.htaccessRewriteEngine On RewriteBase /ci RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]
I am working on codeigniter 3.1.6.I added the .htaccess file. I also changed thebase_urlpath to my project path, removed theindex.phpfromindex_pageand changed theurl_protocoltoREQUEST_URI.Still, while I am redirecting the url to any controllers method it throwing an error as 'The page you requested was not found.'I also searched and applied different .htaccess but its not working. If I am addling/index.phpat end of base_url then its working but its wrong though. It should work without index.php.Only 3.1.6 giving this issue.note: codeigniter-3.1.4 is working properly only this version is giving an issue
Codeigniter 3.1.6 - How to remove index.php from url
There are a few web based testers available to use, unfortunately, these don't always understand all the syntax to accurately check how it works on a real site.One web based one I like to use is this online tester from Made with Love;http://htaccess.madewithlove.be/It doesn't understand a few items such as %{REQUEST_FILENAME} but for general testing I think it should do the job for you. You copy your code into the box, and you can also submit a url to see what it will rewrite to. If you just want to check syntax errors there are a few web tools available as well.Using web based tools are great for an overall check, but you can't really be sure how it affects a real site until you upload it either to a dev version of the real thing.Just recently I've edited a htaccess file, which showed no syntax errors and worked as expected on the tester, which did not work at all on the real site. Site settings may have an impact and all other things which will not show on a web tool.
I don't have much experience with htaccess rules, some of them are working but when I add a new rule or remove one, how do I test them?? I cannot test it on the actual server. Even in my localhost, I won't be able to test some like https rules, www and other stuff.I can test the rest of url patterns but when I add the www and https rules along with the tested ones on the live server, it gives an error and then I continue testing them on the live server.Is there a way to test them without using the actual server and not create another server for testing those rules. Something like a htaccess rule checker or something!?
Better way to test .htaccess file
You can simply rewrite the requests withRewriteCond %{REQUEST_URI} !^/slimapp/public RewriteRule ^slimapp/(.*)$ /slimapp/public/$1 [L]This will serve the appropriatepublicfolder, without redirecting the client. TheRewriteCondis needed to avoid a redirect loop.
I am using Slim Framework v3. I've set up API and its working smoothly if I accesshttp://localhost:8080/slimapp/publicI have default directory structure. My Sample API endpoint ishttp://localhost:8080/slimapp/public/cardswhich returns JSON response of my cardsHow Could I change thepublicfolder to the domain, So I would be able to access my cards endpoint withhttp://localhost:8080/slimapp/cards?
Slim Framework /public folder redirect
Just change.*to.+to make sure your regex pattern isn't matcinng landing page:RewriteRule (.+) http://www.siteb.com/$1 [R=301,L,NE]
I have just merged two websites. Site A is now merged with site B.Site A has got a .htaccess file which redirects all of the content to the new domain where site B is hosted.RewriteRule (.*) http://www.siteb.com/$1 [R=301,L]It is working perfectly, however, I need the homepage of site A not to redirect.What do I need to add to the code above to make that happen?
.htaccess redirect all pages except the home page
Try with:RewriteCond %{QUERY_STRING} ^p=(.*) RewriteRule ^page/(.*)\.html$ /rewrites/page.php?selection=$1&pagination=%1 [NC,L]RewriteRule backreferences: These are backreferences of the form $N (0 <= N <= 9), which provide access to the grouped parts (in parentheses) of the pattern, from the RewriteRule which is subject to the current set of RewriteCond conditions..RewriteCond backreferences: These are backreferences of the form %N (1 <= N <= 9), which provide access to the grouped parts (again, in parentheses) of the pattern, from the last matched RewriteCond in the current set of conditions.http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
I try to get call a page with this structure:/page/my-selection.html?p=1 /page/my-selection2.html?p=3 /page/my-selection3.html?p=6where my-selection, my-selection2, ... is a database key and p the pagination. I want to redirect this on one single page, which does all the magic, but how i can use mod_rewrite to use the variables from both RewriteCond's?I tried it this way, bit it doesn't work:RewriteCond %{REQUEST_URI} page/(.*)\.html [NC] RewriteCond %{QUERY_STRING} ^p=(.*) RewriteRule page/(.*)\.html$ /rewrites/page.php?selection=$1&pagination=$2 [NC]Examples:/page/my-selection.html?p=1 should redirect to /rewrites/page.php?selection=my-selection&pagination=1/page/my-selection2.html?p=3 should redirect to /rewrites/page.php?selection=my-selection2&pagination=3/page/my-selection3.html?p=6 should redirect to/rewrites/page.php?selection=my-selection3&pagination=6Any Ideas?!
.htaccess use parameter from request_uri and query_string
You can use a Rule to set the Env variable:RewriteEngine on RewriteRule ^ - [E=DBL:mysql\:dbname=oars\;host=%{SERVER_ADDR}\;port=3306] print getenv("DBL"); mysql:dbname=oars;host=1.2.3.4.5;port=3306
I am planning to use a single.htaccessfile which may be deployed on multiple servers. In the process I am setting environment variables in the.htaccessfile and there are a couple of cases where I would like to read the IP address into the settings. For instance, in one case I am setting an environment variable for the local database connection:SetEnv DBL "mysql:dbname=oars;host=192.168.101.1;port=3306"Then in PHP I would read the variable for use by the database interactions:define('DBL', getenv('DBL'));Since I am planning to deploy on multiple servers is there a way to get the IP address automagically rather than maintaining separate .htaccess files for each server?
How can I read the local IP address into an .htaccess file?
The first rule is taking precedence overhttpsrequest because it simply met the rewrite condition. The first rule basically tells that match the domain and you can have your rewriterule to kick off. Instead add another condition which tells if its nothttpsrequestSo try this:RewriteEngine on RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteCond %{SERVER_PORT} !^443 RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteCond %{SERVER_PORT} ^443 RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]You need ssl certificate forhttpsprotocol to workAlso I've added[L]flag which tells to not process further rules
I'm attempting to redirect www to non-www for both HTTP and HTTPS requests. My root .htaccess looks like this:RewriteEngine on RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteRule ^(.*)$ http://example.com/$1 [R=301] RewriteCond %{HTTP_HOST} ^www.example.com$ RewriteCond %{SERVER_PORT} ^443 RewriteRule ^(.*)$ https://example.com/$1 [R=301]This isn't fully working as expected. What happens:Visitinghttp://www.example.comresults in a redirect tohttp://example.com. This indicates my first rule and condition are working, the mod_rewite module is hunky-dory and .htaccess is enabled OK.Visitinghttps://www.example.comdoesn't result in a redirect. I remain onhttps://www.example.comMy questionIn order for the above rewrite rules to work, must my server have an SSL certificate? It currently doesn't and I'm wondering if that is the reason things aren't working.
Redirecting www to non-www while maintaining the protocol HTTP or HTTPS
This was due to a corrupted file. Recreating the file worked.
I have a basic .htaccess file. If I leave it empty the page loads correctly. If I have a conditional statement in there (e.g.:)<IfModule mod_filter.c> #Intentionally left blank </IfModule>I get a 500 error.So even though the mod_filter exists and is loaded it dies. Even though there is nothing in the IfModule statement.It's almost as if the<IfModule>statement itself isn't working.This is on 32bit WAMP on Windows.I have other sites running locally that do have full htaccess files, and they work, but this one just won't play!Any one seen this before?!
htaccess IfModule conditional fails
Useurldecode()PHP function before you query it into your database. Like that:<?php $date1 = urldecode($_GET["from_date"]); $date2 = urldecode($_GET["to_date"]); ?>
I have two input in my form.Input 1 value = '02/03/2015' // Both are date Input 1 value = '04/03/2015' // Both are dateWhen I try to submit this form by GET or POST method, url in on my vps changed to this one:from_date=02%252F03%252F2015&to_date=05%252F03%252F2015and on localhost:from_date=04%2F03%2F2015&to_date=04%2F03%2F2015Actually the problem is '/' is double encoded in url on VPS which is breaking my sql queries. Any help is appreciable.
URL slash '/' get double encoded. Changed to %252F instead of %2F
FallbackResourcedoesn't support exclusions like this. You can usemod_rewriteas an alternative.You can use this rule in yourDOCUMENT_ROOT/.htaccessfile:RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !^exclude index.php [L,NC]
I have used FallbackResource /index.php in htaccess to re-route every call to index.phpit works very fine and I am getting the result that I wanted, but I need one directory to access and that directory also re-routes to index.php. How can I achieve this.
route everything to index.php except one directory using FallbackResource
+25As long as you can configure your domain records to point both chat and profile subdomains to your server then you can change the htaccess file in your webroot folder and add..<IfModule mod_rewrite.c> #standard cake htaccess stuff ... RewriteCond %{HTTP_HOST} ^profile\.thechatfun\.com$ [NC] RewriteRule ^(.*)$ http://www.thechatfun.com/users/profile/$1 [R=301,L] RewriteCond %{HTTP_HOST} ^chat\.thechatfun\.com$ [NC] RewriteRule ^(.*)$ http://www.thechatfun.com/chats/index/$1 [R=301,L] </IfModule>I have this exact requirement and this works for me.
CakePHP version-2.5.5My domain name ishttp://www.thechatfun.comProfile page link -http://www.thechatfun.com/users/profileChat page link -http://www.thechatfun.com/chats/indexAbove two link i want to looks likehttp://profile.thechatfun.comandhttp://www.chat.thechatfun.comI am unable to make subdomain in the CakePHP.Please help meThanks ChatFun
How to create a sub-domain in CakePHP?
You're blocking.htaccessbut accessinghttp://localhost/cms/htaccessTry accessinghttp://localhost/cms/.htaccessIf you want to block both try thisFilesMatchdirective with regex:<FilesMatch "\.?htaccess$"> order allow,deny deny from all </FilesMatch>
i need to prevent access to.htaccessfile. my file is:# secure htaccess file <Files .htaccess> order allow,deny deny from all </Files> # disable directory browsing Options All -Indexeswhen i check URL :http://localhost/cms/htaccessI see.htaccessfile dataHow do i canprevent/denyaccess to.htaccessfile?
Prevent direct access to .htaccess file
You can use this rule as yourfirst rule:RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTPS}s on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I want to redirect all non-www to www - if the request is through http it should redirect tohttp://www.domain.com, if the request is through https then direct tohttps://www.domain.comI have tried the following in my .htaccess, but it redirects everything to httpsRewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301I have used this code and it's resolving perfectly. Please check whether it's correct or not.RewriteEngine On RewriteBase / #Redirect non-www to www RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] # Redirect to HTTPS RewriteCond %{HTTPS} off RewriteRule (.*) https://www.pnrstatusbuzz.in/%{REQUEST_URI}
Redirect all non-www to www for both http and https with .htaccess
You can't add rewrite flags to theRedirectMatchdirective. The rewrite stuff is part of mod_rewrite, the redirect stuff is part of mod_alias. If you want to use 'L', you can use mod_rewrite insteadRewriteEngine On RewriteRule ^(folder1|folder2)($|/.*) http://fedmich.com/$1$2 [L,R=301]But I'm not understanding the underlying problem ofwhyyou'd need theLflag here. Are there other rules that you don't want to get applied?
Need some help to add theLAST or Lflag together with the 301 on that RedirectMatch.The code I'm using, which looks like below works, but only have301statusRedirectMatch 301 ^/(folder1|folder2)($|/.*) http://fedmich.com/$1$2I've tried these variations and they don't work or have Internal server error.RedirectMatch 301 ^/(folder1|folder2)($|/.*) http://fedmich.com/$1$2 #not working RedirectMatch [R=301,L] ^/(folder1|folder2)($|/.*) http://fedmich.com/$1$2 #SERVER error RewriteRule ^/(folder1|folder2)($|/.*) http://fedmich.com/$1$2 [R=301,L] #No error, but not redirecting at allI'm scanningpage headerson every tests codes I make so it's not being "cached" and not redirected incorrectly.Thanks guysReferencesRedirectMatchhttp://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirectmatchFLAGS -http://httpd.apache.org/docs/current/rewrite/flags.html
RedirectMatch and including L flag
Have you Apache directiveAllowOverride Allconfigured for this directory ?
I have Apache set up on my own Centos server with several virtual web servers, and I wish to enable PHP short tags for only one of those web servers which is located at/var/www/ostickets/html. I can successfully enable short tags by addingshort_open_tag=Onto php.ini, however, I don't wish to globally do so, but only the one site. I've tried the following, however, nothing is displayed. I've looked at various logs, and cannot detect any errors. Is it possible that I inadvertently disabled the ability to do so and if so how do I allow it (reference "If you don't have access to the php.ini you can try to enable them trough the .htaccess file but it's possible the hosting company disabled this if you are on shared hosting:").[root@vps html]# pwd /var/www/ostickets/html [root@vps html]# ls -la .hta* -rw-r--r-- 1 root root 60 Oct 1 07:38 .htaccess [root@vps html]# cat .htaccess # php_flag short_open_tag on php_value short_open_tag 1 [root@vps html]# cat test.php <? echo('Hello World');?> [root@vps html]#
Enable PHP short tags using .htaccess
Use:RewriteEngine On RewriteRule ^works/(.*)$ works/show.php?slug=$1 [L]You can also put your .htaccess file intoworksfolder with this code:RewriteEngine On RewriteRule ^(.*)$ show.php?slug=$1 [L]
I have some URLs like this:www.mydomain/works/show.php?slug=title-of-the-workI'll like to have htaccess convert to seo URLs in this way:www.mydomain/works/title-of-the-workIn my database I have created a field called slug for every work entry. The first URL works fine.This is how my .htaccess currently looks (it is placed in my root directory):RewriteEngine On RewriteRule /works/(.*)$ /works/show.php?slug=$1I've read and tried a lot of similar examples during the last 24hours to no avail. I'm sure my server allows rewriting, because I can for example rewrite non-www to www URLs. Hope someone can help. Thanks
htaccess rewrite slug to seo url
You want:RewriteRule ^xampp/test/dra/?$ /xampp/test/draft.php [NC,L]Or simply:RewriteRule dra/?$ /xampp/test/draft.php [NC,L]TheRewriteRuletakes from what comes afterdomain/in your case it would what comes afterhttp://127.0.0.1/orhttp://localhost/.Also this rule is not to change your draft.php, this rule you have is to allow you to access:http://localhost/xampp/test/dra/And have your draft.php serve it without showing it.
I've look through the tutorials in web, and below is what I had done to test if mod_rewrite work.First: Uncomment the mod_rewrite.so(@httpd.conf)Second: Allowoverride -> Allowoverride all(@httpd.conf)Third:(@.htaccess)<IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine on RewriteRule ^dra/?$ draft.php [NC,L] </IfModule>finally: if my code work the url should be rewritten tolocalhost/xampp/test/dra/according to (editted from)url-rewriting for beginnerFinal result: mod_rewrite not working, as you can see in the picture. Anything that I had left out?
mod_rewrite not working xampp (with picture)
Are you making the request from the same domain as the page is hosted on? If not, you might be running into a problem withCross-Origin Resource Sharing.To fix this, you might be able to addAccess-Control-Allow-Origin: *as a header.
When I access the following url via browser it works fine returning JSON data,http://azcvoices.com/topcompanies/wp-content/themes/topcompanies/get.php?p=33When jquery does an ajaxgetit is failing with a404 Not found errorwith the following code even when the fileget.phptruly exists on the server as mentioned above,$.ajax( { url: "http://azcvoices.com/topcompanies/wp-content/themes/topcompanies/get.php", type: "GET", data: {p: postId} }) .done(function(post) { }) .fail(function() { alert("error"); }) .always(function() { });You may see the 404 error below,Currently the .htaccess has the following in it,RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] # uploaded files RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L] RewriteRule ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L] RewriteRule . index.php [L]Could this be causing the issue?The same demo on the test server at,http://peplamb.com/workspace/azcentral.com/spotlight-stories/works fine, but the same code is failing athttp://azcvoices.com/topcompanies/spotlight-stories/What could be the issue? Any help is greatly appreciated!
Why is jQuery ajax get returning a 404 Not found error even while the file exists on the server?
how shall i combine the above two conditions & rules in a single .htaccess file?Just put one after the other in the same file:RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.subsite\.site\.com$ [NC] RewriteRule ^/?$ /directory/subdirectory/ [R=301,L] RewriteCond %{HTTP_HOST} ^subsite.site\.com [NC] RewriteRule ^(.*)$ http://www.subsite.site.com/$1 [R=301,L]
i have sub-site namedsubsite.site.com(just and example). firstly i want to redirectsubsite.site.comtowww.subsite.site.comand and finally i want to redirectwww.subsite.site.comtowww.subsite.site.com/directory/subdirectory/index.htmlthe following rewrite conditions & rules serve this purpose independently.RewriteEngine on RewriteCond %{HTTP_HOST} ^subsite.site\.com RewriteRule ^(.*)$ http://www.subsite.site.com/$1 [R=301,L]RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.subsite\.site\.com$ RewriteRule ^/?$ "http\:\/\/www\.subsite\.site\.com\/directory\/subdirectory\/" [R=301,Lhow shall i combine the above two conditions & rules in a single.htaccessfile?thanks,
How to write multiple rewrite conditions and rules in one .htaccess file for redirecting urls?
Just remove theR=301from the flag. This is what causes the external redirect.You will also need to not use the full URL likehttp://example.com. Just use the URI for the resource you want to redirect to.
I would like to make an internal redirect from one URL to another using mod_rewrite in my .htaccess file. Currently I know how to perform the external redirect with the following:RewriteRule ^incoming-controller/action1.*$ http://example.com/incoming-controller/action2 [R=301,L]I want this to happen internally, so the user posts to action1 while apache internally serves the request to action2. Is this possible? I have read about the [P] flag and mod_proxy but I haven't been able to find much documentation on how to use it properly, or if it's useful in this situation.
Internal mod_rewrite, no redirection
admin/.htaccess:RewriteCond %{REQUEST_FILENAME} !check_auth.php RewriteCond %{REQUEST_FILENAME} -f RewriteRule .* check_auth.php?file=$0 [QSA,L] # pass everything thru phpadmin/check_auth.php:$file = $_GET['file']; if($_SESSION['user_authenticated']) { // please mind you need to add extra security checks here (see comments below) readfile($file); // if it's php include it. you may need to extend this code }else{ // bad auth error }
I have an ADMIN script.admin/index.phpAll activity is done through thisindex.phpfile.Users are logging in before gaining access to the program functionality.$_SESSION['user_authenticated']is created and set totrue.admin/template/..This folder containsimages,css,javascriptfiles.They are used only within this ADMIN. (in the backend only)The question:I need all the content fromadmin/template/..directory to be protected againstdirect access.It should be available only to authenticated users.I guess there has to be a.htaccessredirecting requests tocheck_session_auth_variable.php, which looks if$_SESSION['user_authenticated']istrueorfalseandredirects to requested fileorthrows a 404 error?I know that the best option would be to place the directory outside of the web root, but in my case I need to keep the directory structure as is, without modification.
PHP protect directory from direct URL access
You put the .htaccess in the folder whose behavior you want to alter. This also affects the behavior of all the sub-folders. It can happen that you want different behavior for one or more of the sub-folders in which case you give them their own .htaccess file and override the settings that are not to be inherited from the parent.
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed11 years ago.Improve this questionI noticed that I had two.htaccessfile on my website's server, one in the root folder, one in thewwwfolder. Which one is active and which one should I delete?
Where should an `.htaccess` file be located? [closed]
If the questioner starts rewrite ruling with[R=301]301 redirect, a.k.a.“Permanently Redirect”, and then he try to view his URLwww.parkeddomain1.com/subfolder/but the result of the rule wasn't what he want, then even he try to change the redirecting rule, his web browser will always redirect that URL into the first URL where it redirecting with[R=301]flag. Because once the browser has been redirected permanently to the wrong address, even how many times you edit the rule, your browser will still be redirected to the old address, that's a browser thing, and you may even go on to fix the rule, and then change the rule all over again without ever knowing it. Changes the 301 redirects in your browser can take a long time to show up.The solution is to restart the web browser, or use a different one. So, if you're testing, it's better to use a[R]flag instead of[R=301]flag. And when you are 100% sure that the rule does exactly as it's expected to, then switch it to[R=301]flag. Or else, this question belongs toServer Fault.
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed10 years ago.Improve this questionMy problem seems simple to me but I cannot find a simple solution. Here goes: I have one main domain, and multiple domains pointing to that main domain. To avoid duplicate content I'm trying to redirect all "secondary" or "parked" domains to my main domain so that it resolves to this:www.parkeddomain1.com => www.maindomain.comwww.parkeddomain2.com => www.maindomain.comwww.parkeddomain3.com => www.maindomain.comAnd so on...Now I have found this htaccess code that is sort of a catch-all solution (which I would prefer):RewriteEngine on RewriteCond %{HTTP_HOST} !^www.maindomain.com$ RewriteRule ^(.*)$ http://www.maindomain.com/$1 [R=301]So this code works when I'm dealing only with straightforward parked domains, not with parked domains with subfolders or subfiles. So:www.parkeddomain1.com => www.maindomain.comredirect works fine here but when I add a subfolder this happens:www.parkeddomain1.com/subfolder/ => www.parkeddomain1.com/subfolder/when what I'm looking for is:www.parkeddomain1.com/subfolder/ => www.maindomain.com/subfolder/All this in order to avoid the duplicate content problem with search engines.Thanks to all for any answer that would guide me to a solution.Cheers!
The Redirection of Multiple Parked Domains doesn't Work with Filename [closed]
This is probably because of themod_dir and theDirectorySlashdirectivethat's doing the redirect. With it on, when apache looks at a URI and thinks it's accessing a directory, and is missing the trailing slash, it 301 redirects to the URI with the trailing slash. It's always turned on by default because there's an information disclosure security issue if you have it turned off. But if you are routing everything through an index.php script, it may not even matter and you can turn it off by simply addingDirectorySlash Offin your htaccess file (and turn it on for directories that you can access directory, like css or js or images, etc.
A request tohttp://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websitesgets redirected as follows:> Request URL:http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites > Request Method:GET > Status Code:301 Moved PermanentlyResponse headers:> HTTP/1.1 301 Moved Permanently Date: Thu, 06 Sep 2012 14:32:41 GMT > Server: Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 > mod_perl/2.0.4 Perl/v5.10.1 Location: > http://localhost/SAMPLE-CODES/backbone-mysql-reading-json/websites/ > Content-Length: 417 Keep-Alive: timeout=5, max=100 Connection: > Keep-Alive Content-Type: text/html; charset=iso-8859-1I am not sure what causes this redirect.I have the following .htaccess in folderc:\xampp\htdocs\SAMPLE-CODES\backbone-mysql-reading-json\:.htaccessRewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L]
Why do I get a 301 redirect to folder name with slash?
Take a look at somemod_security and .htaccess tricks. There's a lot of different ways you can enable or disable mod_sceurity. The easiest may be to set theMODSEC_ENABLEenvironment variable toOnorOff. You can useSetEnvIfto match against a number of things including theRequest_URI:SetEnvIf Request_URI your_page\.php$ MODSEC_ENABLE=OffOr a number of pages:SetEnvIf Request_URI ^/directory/file.*\.php$ MODSEC_ENABLE=OffOr if you need to do something more complicated, like matching against a query string,using mod_rewrite:RewriteEngine On RewriteCond %{QUERY_STRING} example_param=example_value [NC] RewriteRule ^path/your_file\.php$ - [E=MODSEC_ENABLE:Off]
My page showing error forbidden access error, when I post somehtmlandjavascriptmixed data by other page post method .but when I open that page directly its appears correctly without any error.I know this is server security related issue when I am posting data.As I searched I found the solution ofTurn off mod_securityin .htaccessfile .But I want to do this just for this page not for my complete website.My hosing environment is shared.but I can edit my .htaccessfile.
Turn off mod_security for a page in shared hosting environment
Use an environment variable for theuser that runs Apache,#.profile of Apache user rewritebase = "some/path"then refer to it inside your .htaccess file:#.htaccess file RewriteBase {$rewritebase} RewriteRule ^(.*)$ - [E=cache:%{ENV:rewritebase}cache]A pseudo ReWriteRule can also do the trick:#This will be true for any user agent RewriteCond %{HTTP_USER_AGENT} ^.* #Replace / with / and set the rewritebase variable to /some/path RewriteRule /(\/some\/path)* / [E=rewritebase:$1/some/path] #Reference the rewritebase variable RewriteBase {$rewritebase} #Redefine the rewritebase variable RewriteRule ^(.*)$ - [E=rewritebase:$1]
I'm writing an .htaccess file that will check if a requested page exists in a cache or not. In order to perform the check (and save typing), I'm setting an ENV variable with the location of the cache:# all this works as I expect # <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /some/path/ RewriteRule ^(.*)$ - [E=rewritebase:/some/path/,E=cache:%{ENV:rewritebase}cache/] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{ENV:cache}$1\.html -f RewriteRule ^(.*)$ $1\.html [L] </IfModule>As you can see, I'm also having to set an ENV variable to "stand in" for the RewriteBase value. I'd rather not, since if the RewriteBase is changed, I'd have to remember change the ENV variable also. Eventually, this may be a part of a CMS used by others, which I wish to be as simple/straightforward as possible to configure, with the fewest opportunities for error. I'd like to be able to set only theENV:cachevariablewithoutthe need for setting anENV:rewritebasevariable, like so (or similar):# doesn't work # RewriteRule ^(.*)$ - [E=cache:%{RewriteBase}cache/]As implied, thecache/directory will always be located inside the directory specified in RewriteBase. [edit]. . . however, it willnotalways be the physical path where this .htaccess file exists.[/edit]I'd be happy to hear alternative suggestions, as well. Thanks, everyone!
is the value of RewriteBase available as a variable/reference?
Use this:RewriteEngine on RewriteRule ^user/([a-zA-Z0-9]+)$ /user/profile.php?usr=$1 [L,QSA]The issue is that you are using an absolute URL, instead of a relative URL, and mod_rewrite is performing a redirect instead of a rewrite.
I want it so when I write the following:http://boundsblazer.com/user/joeit internally processes the page:http://boundsblazer.com/user/profile?usr=joeBut keeps the old URL. However, when I write:http://boundsblazer.com/user/joethe URL becomes:http://boundsblazer.com/user/profile?usr=joeI have searched countless threads, and nobody is having the trouble I am. The problem is that when I write my URL, the URL changes and makes it look ugly. This is my.htaccess:RewriteEngine on RewriteRule ^user/([a-zA-Z0-9]+)$ http://boundsblazer.com/user/profile.php?usr=$1 [L,QSA]Does anyone know what could be causing the problem?
.htaccess rewrite URL not showing correctly?
You can use .htaccess for this. For example:RewriteEngine On RewriteRule ^questions/(\d+)/([a-z-]+) index.php?id=$1&title=$2 [L]Your PHP page (index.php) receives the id and title as parameters in$_GET[]:echo $_GET['title']; // get-the-title-of-a-page-urlYou can then use that (or the id, which is easier) to retrieve the correct item from your data source:// Assuming you didn't store the - in the database, replace them with spaces $real_title = str_replace("-", " ", $_GET['title']); $real_title = mysql_real_escape_string($real_title); // Query it with something like SELECT * FROM tbl WHERE LOWER(title) = '$real_title';Assuming you do have an id parameter in the URL of some sort, it's easier to query based on that value. The title portion can be used really only to make a readable URL, without needing to act on it in PHP.In reverse, to convert the title to theformat-like-this-to-use-in-urls, do:$url_title = strtolower(str_replace(' ', '-', $original_title));The above assumes your titles don't include any characters that are illegal in a URL...$article_link = "http://example.com/spowpost.php?post=$postid&$title=$url_title";Or to feed to .htaccess:$article_link = "http://example.com/spowpost$postid/$url_title";
I want to apply the page HTML title in the URLfor example in here (stackoverflow) the url is something like that:http://stackoverflow.com/questions/10000000/get-the-title-of-a-page-urlyou can see the "get-the-title-of-a-page-url" part which is the page titlewhat i mean is when the user go to spowpost.php?post=1the actual url that shows up when the pages load will be spowpost.php?post=1$title=..the_title..how can i do that?EDIT: i was thinking about htaccess , but i don't know this very well so tutorial would help for this CERTAIN case..
PHP , htaccess: apply page title in URL
This one is based on your example with minor modification:RewriteEngine On RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC] RewriteRule ^(.*) http://www.domain.com/$1 [R=301,NE,L]NC,R=301andLare pretty obvious. TheNEis for no-escape and it prevents query string variables from being escaped twice. The^(.*)does not need a/in most cases.Note: 301 permanent redirect responses will be cached by the browser so clear your browser cache every now and then while testing. Otherwise you may not see the result of changes you make.
\I'm darn nearly pulling my hair out trying to figure this out tonight. I'm hoping someone can help me out.I have 3 TLD's for a site, similar to the following:www.domain.comwww.domain.orgwww.domain.netThey are all located in the same directory.I would like to set up 301 redirects so that all pages of the .org and .net point to their respective pages at the .com location.For example, domain.net/topic/page as well as www.domain.net/topic/page should permanently redirect to www.domain.com/topic/page.Currently, I am using the code below which only redirects the .net and .org home pages to the .com home page.RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC] RewriteRule .?$ http://www.domain.com%{REQUEST_URI} [R=301,L]Thank you for your time,Casey
Redirect all pages of one TLD to another
I now see the problem. You are rewriting a URL fromhttp://www.example.com/tohttp://www.example.com/shows. Since/showsis a directory and not a file, Apache sends atrailing slashredirect after rewriting. Here is How you fix it:RewriteRule ^$ shows/ [L] # here -------------^Note: since Apache might have sent a301 Moved Permanentlyheader earlier, browsers will cache this response and it might show you wrong page/content even after you make changes to your .htaccess file. Clear browser cache often when you're testing.
I am using the following mod_rewrite to redirect from the top directory of my site, to the subdirectoryshows/:Options +FollowSymlinks RewriteEngine On RewriteRule ^$ shows [L]The redirect is performing fine. However, the URL isdisplayingthe redirect, which I believe it should not if you use mod_rewrite.To clarify: A browser pointed towardshttp://www.example.com/is redirected to the subdirectoryshows/. But the browser displays the redirect in the URL ashttp://www.example.com/shows/. Again, it is my understanding that by using mod-rewrite, you make the redirect invisible, so the user is not aware the redirect has taken place.Am I doing something wrong?
mod_rewrite is redirecting the browser instead of rewriting
# don't show any files in the folder IndexIgnore * ErrorDocument 403 / ErrorDocument 404 / RewriteEngine On # disabled user to access directly to the files folder. RewriteRule ^files(\/?)$ - [F] # images RewriteRule ^image/(.*)\.(jpg|png|jpeg|gif)$ /files/$1.$2 [L] # video RewriteRule ^video/(.*)\.(flv|avi|mov)$ /files/$1.$2 [L] #etc...If you have sub folders, the(.*)will automatically use it. Example:http://www.domain.com/image/i.png => /files/i.png http://www.domain.com/image/sub1/sub2/i.png => /files/sub1/sub2/i.pngHere some links that will help you:http://www.javascriptkit.com/howto/htaccess.shtmlhttp://www.htaccess-guide.com/http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/http://www.bloghash.com/2006/11/beginners-guide-to-htaccess-file-with-examples/
Basically I have a CDN setup./public_html/ index.html /files/ image/ video/ video2/video2I want to redirect ALL sub folders and directories to the main folder - except file extensions, so if someone loads a file, I want that to load, just so people cant view directories. (I dont want to see a 404 or forbidden message, just want the directory to go to the main page)It would save me from uploading index.php redirects. Can this be done with .htaccess?
How do I redirect all Sub folders and directories to the main root excluding files?
Just make sure your script generates the appropriateContent-Typeheader. You can do so withheader().
Here's the problem I'm trying to solve: I have a dynamic php-driven website that is constantly being updated with new content, and I want my XML sitemap to stay up to date automatically. Two options I see:Write a php script that queries my database to get all my content and outputs tohttp://mysite.com/sitemap.xml, execute the script regularly using a cron job.Simply create my sitemap as a php file (sitemap.php), query the db and write directly to that file, and use the htaccess rewrite ruleRewriteRule ^sitemap.xml$ sitemap.phpso that whenever someone requests sitemap.xml they're directed to the php file and get a fresh sitemap file.I'd much rather go with option #2 since it's simpler and doesn't require setting up a cron, but I'm wondering if Googlebot will not recognize sitemap.xml as valid if it's actually a php file?Does anyone know if option #2 would work, and if not whether there's some better way to automatically create an up-to-date sitemap.xml file? I'm really surprised how much trouble I've had with this... Thanks!
Using htaccess to "fake" an XML file?
The correct answer is:<FilesMatch "^\.html"> Order deny,allow </FilesMatch> DirectoryIndex .html
I have a Debian web-server with Apache2 installed and need to set in one directory DirectoryIndex to .html file (exactly this name - .html). But when I try to open page from browser it send 403 error. I've changed apache2.conf (set to allow .ht files), I placed .htacess file in directory and set in it:DirectoryIndex .html index.php index.html AllowOverride All Order Deny,Allow Allow from allBut it still not work and displays 403 error. What i doing wrong and what i forget to do?
Set directory index to .html file in Apache2
I had the same issue recently and what ultimately did the fix was to simply rename the file for the purpose of uploading (for example .htaccess-new), then rename it back to .htaccess on the live server.Be sure to save a back up of the original file, and make certain the file permissions match the original (or are set to whatever you might need.)
I am using Amazon EC2 server. Set up a Ubuntu system and ProFTPD Server. Then I create an user to upload files. It works.But I can't upload .htaccess file. It returns the following error:Response: 257 "/public_html" is the current directory Command: TYPE A Response: 200 Type set to A Command: PORT 192,168,1,2,200,20 Response: 200 PORT command successful Command: STOR .htaccess Response: 550 .htaccess: Permission denied Error: Critical error Status: Disconnected from serverI am managing things via webmin and through Terminal via ssh. I tried following steps:DenyFilter *.*/ (Commented this line on the config file of FTP)Added GLOBAL like this: ListOptions "-la"But nothing works.An interesting thing is, I can upload .htaccess file to other directories except "public_html"..
FTP Server doesn't allow me to upload .htaccess file
Don't put a question mark in your URLs. The?is reserved for the start of the query string.To place it in a URL, encode it as%3F.Read theRFCandthis answer.UpdateIf using PHP (and it looks like you are), you could do something like this (page requested isindex.php/inter?net)...<?php var_dump($_GET); $urlTokens = explode('/', $_SERVER['REQUEST_URI']); $slug = end($urlTokens); var_dump($slug);Outputsarray(1) { ["net"]=> string(0) "" } string(9) "inter?net"You can see$_GETis confused.
I need to escape the "?" character in the url, so that it works with rewritten urls like search/why-is-it?-1.htmlI currently have the following in .htaccessRewriteEngine on RewriteRule ^search/(.*)-([0-9]+).html$ index.php?search=$1&page=$2 [L]Thanks
How to escape "?" using regex in .htaccess for mod_rewrite
I had this same question, and I also found this related question:htaccess rewrite and auth conflictOne of the answers there clued me into my problem. Apache was trying to find a document for the 401 error and failing. I added a document /401.html and added this to the .htaccess file with the Auth statements.ErrorDocument 401 /401.htmlNow, it works for me!
I have a site which redirects all requests for files/folders which don't exist to an index file using .htaccess:RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule !admin/* index.php [NC,L]There is a folder "admin/" which has the following in .htaccess for auth:AuthType Basic AuthName "admin" AuthUserFile "/path/to/passwd" require valid-userAdding the auth .htaccess file in "admin/" causes the request to be trapped by mod-rewrite instead of providing the authentication response. I've tried a few different things trying to work around this (including this:htaccess rewrite and auth conflict), but couldn't get any purchase.Thanks.EDIT:If I'm already authenticated, the rewrite ruleworksallowing me to access the "admin/" folder. So it seems that it's the authentication challenge that's doing something wonky.
.htaccess mod-rewrite conflicting with subfolder auth
I would suggest just linking to the old cms from inside drupal.And keep the folders of the old cms outside of the drupal folders. Your old cms also probably doesn't reference the links correctly (its expectinghttp://oldcmslinkand inside of drupal it would behttp://drupal?q=something).
I'm a drupal newbie...I completed my first drupal site. then client wanted to run their old CRM under new drupal site, they uploaded CRM folder into drupal folder, and when I try to address the CRM admin, as below, it redirects drupal 404 page (which is search page).www.blablabla.com/crm/adminError message from drupal is below:The page you requested does not exist. For your convenience, a search was performed using the query 500 shtml.is there any way that I can make drupal to ignore any folder under its folder? something via .htaccess, or I don't know :/Appreciate helps so much! thanks a lot!
Running a different CMS system under drupal folder
You need to swap your code blocks around. The[L]flag on the WordPress rules are stopping execution of the file at that line in their code since your special path would "pass" the WordPressREWRITE_CONDstatements:RewriteEngine On RewriteCond %{HTTP_HOST} burrowpress.com$ [NC] RewriteCond %{REQUEST_URI} !^/burrowpress/.*$ RewriteRule ^(.*)$ /burrowpress/$1 [L] # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPressYou don't need twoRewriteEngine Onstatements, but since WordPress is able to rewrite your.htaccessfile (depending on how you have it setup) you might want to leave it. If you are updating your file manually, you can remove the secondRewriteEngine ondirective.Theimportantpart is that I moved your special rules ahead of wordpress.
I'm trying to combine the following code so that the WordPress permalinks work in the main directory, waringis.com (top code) and a second domain, burrowpress.com, is redirected to the subdirectory 'waringis.com/burrowpress' (bottom code) -<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> RewriteEngine On RewriteCond %{HTTP_HOST} burrowpress.com$ [NC] RewriteCond %{REQUEST_URI} !^/burrowpress/.*$ RewriteRule ^(.*)$ /burrowpress/$1Right now permalinks are working in WordPress and the redirect works but images have to be direct links to waringis.com/burrowpress/images/ instead of burrowpress.com/images/ - Any help is much appreciated...
How do I combine WordPress permalink code and .htaccess redirect?
Maybe this? (needs mod_rewrite)RewriteEngine On RewriteRule !^(special(/.*)?|collector\.html)$ collector.html [R,L]
It's been a while since I've messed with .htaccess and I can't seem to get this quite right. I have a site, say example.com, where I want example.com/* to redirect to example.com/collector.htmlexceptfor URLs under the subdirectory example.com/special, which I want to continue working.For example:example.com/page.html should redirect to example.com/collector.htmlexample.com/foo/bar should redirect to example.com/collector.htmlexample.com/special/page.html should not redirectI would have thought that something likeRedirectMatch 302 ^/[^(special)]/.* /collector.html RedirectMatch 302 ^/[^(collector.html)/]* /collector.htmlwould do the trick, but it doesn't seem to work the way I want it to.
How to use htaccess to redirect all but one subdirectory
In your existing rules you appear to have some stuff the wrong way around, and I don't think there's any need for the negative (i.e.!) test.RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC] RewriteRule ^/blog/$ http://blog.example.com/ [L,R=301]However I'd suggest that you don't use theRewriteConddirective to check the hostname, just make sure the rule is in the rightVirtualHostforwww.example.com.<VirtualHost ...> ServerName www.example.com ServerAlias example.com RewriteRule ^/blog/ http://blog.example.com/ [L,R=301] </VirtualHost>(nb: assumes thatblog.example.comandwww.example.comare actually separate virtual hosts)
WhatRewriteRule(using.htaccess/mod_rewrite) should I use to redirecthttp://example.com/blog/(withwwwor without) tohttp://blog.example.com/?I'm using the following, but getting a redirect loop:RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/blog/ [L,R=301] RewriteCond %{HTTP_HOST} www\.example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/blog/ [L,R=301]
Rewrite URL from http://example.com/blog/ to http://blog.example.com/
This seems to work , anyone review and see if ok<IfModule mod_headers.c> SetEnvIf Origin "http(s)?://(www[1-9][0-9]?\.example\.com)$" AccessControlAllowOrigin=$0 Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin Header merge Vary Origin </IfModule>
I currently have.htaccessfile that lists dozens of domains to enable CORS to from my server.I shortened my example below , but all the domain names are similar and the only part of the domain name that is changed is the 1 or 2 digit number after the www.<IfModule mod_headers.c> SetEnvIf Origin "http(s)?://(www48.example.com||www47.example.com)$" AccessControlAllowOrigin=$0 Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin Header merge Vary Origin </IfModule>so in this example i have CORS enabled forhttps://www48.example.com https://www47.example.comI was wanting a simpler way to enable a list of of 99 domains with similar names. So all domain names are identical aside of digits 1 to 99 after the "www" , how can I achieve this without listing all 99 domain names individually?https://www1.example.com https://www2.example.com .... https://www10.example.com .... https://www40.example.com .... https://www70.example.com .... https://www99.example.com
how to simply a list of about 99 domains to enable CORS on?
To fix the 404 error you're encountering when accessing URLs starting with /admin/*, you need to adjust yourNginx configuration. Here's an updated configuration that should resolve the issue:root /var/www; location /admin { alias /var/www/html/admin; try_files $uri $uri/ /admin/index.html; } location / { try_files $uri $uri.html $uri/ /index.html; }In the updated configuration:The/adminlocation block handles requests for URLs starting with /admin. It uses the alias directive to specify the correct directory path for the app1 located in /var/www/html/admin. The try_files directive is used to check if the requested URI exists as a file or a directory. If not, it will serve /admin/index.html, which is the entry point for app1.The/location block handles requests for all other URLs. The try_files directive checks if the requested URI exists as a file, with .html appended to it, as a directory, or else serves /index.html, which is the entry point for app2.By updating your Nginx configuration as shown above, you should be able to correctly route requests to the respective applications based on the URL path.
I have two build vite react apps.I am going to deploy these in the same domain.For example if the request URL is "https://example.com/admin/*" I should show app1 and for other URLs I should show app2.So I configed .htaccess file like this.<IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On # For URIs starting with /admin, load the app in admin directory RewriteCond %{REQUEST_URI} ^/admin [NC] RewriteRule ^(.*)$ /admin/index.html [L] # For all other URIs, load the app in html directory RewriteCond %{REQUEST_URI} !^/admin [NC] RewriteRule ^(.*)$ /index.html [L] </IfModule>And I am using nginx and nginx config file is like this.root /var/www; location / { try_files $uri.html $uri $uri/ /html/index.html; }The app1 is in/var/www/html/admindirectory and the app2 is invar/www/htmldirectory.But I got the 404 error for/admin/*URL.How to fix this.
How to deploy two build react apps in the same domain with .htaccess
With your shown samples/attempts, please try following htaccess Rules. Please make sure to clear your browser cache before testing your URLs.RewriteEngine ON ##Rules for external rewrite. RewriteCond %{THE_REQUEST} \s/([^.]*)\.php\?id=(\S+)\s [NC] RewriteRule ^ /%1/%2? [R=301,L] ##Rule for internal rewrite. RewriteRule ^([^/]*)/([^/]*)/?$ $1?id=$3 [L]
I have made sure that rewrite engine is enabled and removing .php extensions is working so I know that isn't the issue.what I'm trying to do is simply remove the ?id=value aspect of the URL, so basically making the URL look like such:folder/medias/valueInstead offolder/medias?id=valueMy current .htaccess looks like this:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [NC,L] RewriteRule ^404/?$ /404.php [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^ 404.php [L,R]
Rewrite URLs in .htaccess for replacing Query parameters with forward slash (id?=value)
With your shown samples, please try following htaccess Rules file. Please make sure to clear your browser cache before testing your URLs.RewriteEngine On ##keep redirection Rules first then keep rest of rules. RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php/?$ %{REQUEST_FILENAME}.php [QSA,L] ##Adding new rule here for non-existing pages here. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/?$ index.php?$1 [QSA,L]
I have my URLhttps://example.com/?hfgshdsds.I need to rewrite a rule to makes that even If I removed the question mark , the link will works as same as before, so my url need to behttps://example.com/hfgshdsds.For the moment on my .htaccess file I have only the rule that open the php without extension .php .RewriteEngine On RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [QSA,L]Thank you!
HTACCESS Rewrite Rule for Query String in PHP
Could you please try following, please make sure you clear your browser cache before testing your URLs. This considers your uri starts fromdocs.<IfModule mod_rewrite.c> RewriteEngine ON RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit.*$ [NC] RewriteCond %{REQUEST_URI} ^/docs [NC] RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.*)$ https://sharing.mysite.tld/api/share/$1 [L]In case you want to pass URLs where docs could come anywhere in uri(not from starting what 1st solution looks for), then try following Rules.<IfModule mod_rewrite.c> RewriteEngine ON RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit.*$ [NC] RewriteCond %{REQUEST_URI} docs [NC] RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.*)$ https://sharing.mysite.tld/api/share/$1 [L]
I have a SPA app with dynamic content for sharing on Facebook so I am redirecting Facebook crawlers to a nice static page using the following rule in htaccess:<IfModule mod_rewrite.c> RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit.*$ RewriteRule ^(.*)$ https://sharing.mysite.tld/api/share/$1 [L]This works great! But there is one problem... I can't make my app live because Facebook requires a link to privacy policy, terms and conditions etc - and these get redirected too!!I need to ignore a certain URLs - anything requested in /docs/ - from the above ruleEDIT: so that urls containing /docs/ are followed as normal (no redirect, just served normally).I can't get .htaccess to pick up on the ignore rule. I would have thought this would do it (with thanks tohttps://stackoverflow.com/a/1848579/4881971):RewriteRule ^(docs)($|/) - [L]so I would have thought my .htaccess file would look like this :<IfModule mod_rewrite.c> RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit.*$ RewriteRule ^(docs)($|/) - [L] RewriteRule ^(.*)$ https://sharing.mysite.tld/api/share/$1 [L]but when I use Facebook Object Debugger onhttps://mysite.tld/docs/privacyI get a 404! It redirecting tohttps://sharing.mysite.tld/api/share/docs/privacyHow do I retain the rule but ignore requests from mysite.tld/docs/* ? Thanks.
.htaccess redirect facebook crawlers except privacy policy
You may try this block of rules totally based onmod_rewriterules:RewriteEngine On RewriteCond %{HTTP_HOST} (localhost|domain\.com) [NC] RewriteRule ^ - [E=_rootfolder_:www.domain.com] RewriteCond %{HTTP_HOST} domain\.de [NC] RewriteRule ^ - [E=_rootfolder_:www.domain.de] RewriteRule ^ - [E=_rooturl_:domainname]
I'm trying to set environment variables in my.htaccessfile based on the top level domain of the server. But after there is a match for the condition, the.htaccessfile does not execute further.If there is no domain matched,_rooturl_is set but_rootfolder_is not. However, when a domain is matched_rootfolder_is set but_rooturl_is not. This also applies to any other redirects defined after that.(...) <If "req('Host') =~ /domain.com/ || req('Host') =~ /localhost/"> RewriteRule .* - [E=_rootfolder_:www.domain.com] </If> <If "req('Host') =~ /domain.de/"> RewriteRule .* - [E=_rootfolder_:www.domain.de] </If> RewriteRule .* - [E=_rooturl_:domainname] (...)TL;DR, I want my code to execute after passing the IF conditions.
Set environment variables in .htaccess based on TLD
This is what cPanel does automatically in the.htaccessfile to protect its setup. It just stops your rules from affecting.cpaneldcvfiles, some cPanel text files named with 32 characters.txtand theacme-challengefiles.acme-challengeis indeed likely to do with TLS certificate generation.
Today I noticed that the.htaccessfile in mypublic_htmlroot was modified a couple of months ago.Before everyRewriteRuleline, some bot or somebody has added the following three lines:RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$ RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$ RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$ # lines above were inserted above each rewrite such as the following RewriteRule ^home/? /index.html [QSA,END,NC]I also noticed that I had apublic_html/.well-known/acme-challenge/empty directory. I have two questions.What should I make of this?What effect do the rewrite conditions have? My rewrites still seem to work as before.UpdateIt seems to have to do withLet's EncryptTLS cert auto-renewal, so the folder was probably created by the certification bot. But why do such a hatch job of my.htaccess? the trio of lines I pointed out appears, as I said, beforeeveryrewrite. So it adds a lot of bloat and confusion to the file.
Something unknown added this to my htaccess. What to make of it?
I hope you should visitlocalhost/login.php.try it please.
I am a noobie in PHP, I am setting up a simple Routing using AltoRouter. Below is my index.php and .htaccess file which are at the route folder i.e, /var/www/html/ I am using Apache2 for serving the web pages.index.php<?php require 'vendor/AltoRouter.php'; $router = new AltoRouter(); // map homepage $router->map('GET', '/', function () { require __DIR__ . '/views/home.php'; }); $router->map('GET|POST', '/login', function () { require __DIR__ . '/views/login.php'; }); $router->map('GET', '/signup', function () { require __DIR__ . '/views/signup.php'; }); $match = $router->match(); // call closure or throw 404 status if ($match && is_callable($match['target'])) { call_user_func_array($match['target'], $match['params']); } else { // no route was matched header($_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); } ?>.htaccessRewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php [L]Problem: When I visit localhost, the 'home.php' get served, but when I visit 'localhost/login' or 'localhost/signup', I get 404 error.
PHP AltoRouter serving only base URL
a2enmod rewriteservice apache2 restart
I'm trying to set up a local WP environment on my machine. My .htaccess file (which is in the same folder as my index.php file) looks like this:# 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] </IfModule> # END WordPressMy MAMP database should be set up correctly Every time I try to view the site in my browser, I get:Not FoundThe requested URL /wordpress was not found on this server.My wp-config.php file looks like this:define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'root'); /** MySQL database password */ define('DB_PASSWORD', 'root'); /** MySQL hostname */ define('DB_HOST', 'localhost');I haven't tried to move anything around, so I'm not trying to update permalinks. I've tried changing the ports on MAMP, trying various strings of URLs (including port number, trying to navigate to specific pages within the site, etc. I've tried everything suggested onThe requested URL /about was not found on this serverand WP's guidelines (though they seem to solve issues only after people have installed plugins — I'm just trying to set up the basic initial WP download).Any suggestions? I'm at a total loss for what else to try. Any help is greatly appreciated — thank you!Here's my folder structure (in my sites folder, which is where MAMP is directed):screenshot of folder structure
The requested URL /login was not found on this server
Use this:RewriteEngine On RewriteRule ^ex/([^/]*)\.htm$ /ex.php?ez=$1 [L]It will give you the following URL:example.com/ex/DF004AE.htmIf you meant it to be .html (not .htm) Just add the l in the RewriteRule.
I want to use mod rewrite via htaccess for a PHP website.URL structure is the following:example.com/ex.php?ez=DF004AEIt must become:example.com/ex/DF004AE.htmWhat is the correct script to add to my .htaccess in order to do that?
Using Mod Rewrite to change URL structure
As @Olaf mentioned. changing this:AuthUserFile .htpasswd..into this:AuthUserFile /absolute/server/path/.htpasswd..did the trick. Thank you verry much!
I'm having trouble setting up a .htpasswd protected laravel project.I tried adding the following to my .htaccess but it causes an internal server error (500) after I entered my credentials...htaccess content:AuthUserFile .htpasswd AuthType Basic AuthName "Secured area" Require valid-user <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] # Handle Authorization Header RewriteCond %{HTTP:Authorization} . RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] </IfModule>And this is the current routes.php. Just in case it's something I should change in the routes.php:Route::get('/', 'HomeController@index'); Route::auth(); Route::get('/home', 'HomeController@index');I couldn't find anything useful on Google which still works under laravel 5.2 so I really hope someone out there has an idea :)
Laravel 5.2 - Basic Auth using .htpasswd
Options -Indexes +FollowSymLinks RewriteEngine On RewriteBase / # exclude any paths that are not codeigniter-app related RewriteCond %{REQUEST_URI} !^/server-status RewriteCond %{REQUEST_URI} !^/server-info RewriteCond %{REQUEST_URI} !^/docs RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d <IfModule mod_php5.c> RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> # the following is for rewritting under FastCGI <IfModule !mod_php5.c> RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule>Base on sigmoidhttps://www.npcglib.org/~stathis/blog/2013/08/12/apache-tip-rewriting-urls-with-apache-2-4-php-fpm-mod_fastcgi_handler-codeigniter/
I'm having trouble getting mod_rewrite to work with CodeIgniter. I'm running apache 2.4.My web root is /Users/Jason/Development/wwwThis is the code I currently have in my .htaccess file located in the same directory as my main index.php file.<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /myapp/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule>What am I doing wrong? I keep getting a 404 page saying the requested URL was not found on this server.
CodeIgniter mod_rewrite with apache 2.4
Inside that specific folderyou can create a .htaccess with this rule:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ /public/ [L]
I'm trying to rewrite all requests in a folder like this:https://www.test.com/banana/apple(or whatever) goes tohttps://www.test.com/publicbut in the url is stillhttps://www.test.com/banana/apple.How can I do this?
Rewrite ALL requests to a folder with .htaccess file
You can useRewriteCondlike this:RewriteEngine on # ?debug=1 is present RewriteCond %{QUERY_STRING} (^|&)debug=1\b [NC] RewriteRule (.*) app/webroot/$1 [L] # ?debug=1 is not present RewriteCond %{QUERY_STRING} !(^|&)debug=1\b [NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php?$1 [QSA,L]
Is there a way to make different rewrite rules in.htacessif a certainGETparameter was passed?For example, if query string is:htttp://domain.com/?debug=1, than.htaccessshould look like:<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>If there is nodebug=1in query string, than:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-l RewriteRule !\.(js|ico|gif|jpg|png|css|html|swf|flv|xml)$ index.php?$1 [QSA,L]
Different .htaccess rewrite rules depending on a $_GET param
Put the following code :RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(.*)index\.php\sHTTP.*$ RewriteRule ^ /%1 [R=301,L]
URLs are working fine in my application. I mean they are pretty URLs. Likehttp://www.example.com/But it also works when you access the page withindex.phplikehttp://www.example.com/index.php, which I don't want because it is showing two links in sitemap for one page. One page withoutindex.phpand another withindex.php. Demonstration of the sitemap is herehttps://www.xml-sitemaps.com/details-eln.6762418.htmlHere is the.htaccess<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>
Remove index.php from url Laravel 5
You can't have both the search and profile be the same regex pattern. For example, if someone requests:http://example.com/index/fooAre they trying to go to a page called "foo" or go to a profile of a user named "foo"? You need to add something that separates the two, maybe something like:Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /index\.php\?page=profile&value=([^\s&]+) [NC] RewriteRule ^ profile/%1? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)&type=([^\s&]+) [NC] RewriteRule ^ page/%1/%2? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)(\ |$) [NC] RewriteRule ^ page/%1? [R=302,L,NE] RewriteRule ^profile/([^/]+)/?$ /index.php?page=profile&value=$1 [NC,L,QSA] RewriteRule ^page/([^/]+)/([^/]+)/?$ /index.php?page=$1&type=$2 [NC,L,QSA] RewriteRule ^page/([^/]+)/?$ /index.php?page=$1 [NC,L,QSA]This makes your urls look like:http://example.com/profile/myname http://example.com/page/search http://example.com/page/stats/daily
Rewriting the following 3 URLshttp://example.com/index.php?page=searchtohttp://example.com/searchhttp://example.com/index.php?page=profile&value=mynametohttp://example.com/mynamehttp://example.com/index.php?page=stats&type=dailytohttp://example.com/stats/dailyCurrent .htaccess is written as the following:Options -MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)&value=([^\s&]+) [NC] RewriteRule ^ index/%1/%2? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+)&type=([^\s&]+) [NC] RewriteRule ^ index/%1/%2? [R=302,L,NE] RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC] RewriteRule ^ index/%1/? [R=302,L,NE] RewriteRule ^index/([^/]+)/([^/]+)/?$ /index.php?page=$1&value=$2 [NC,L,QSA] RewriteRule ^index/([^/]+)/([^/]+)/?$ /index.php?page=$1&type=$2 [NC,L,QSA] RewriteRule ^index/([^/]+)/?$ /index.php?page=$1 [NC,L,QSA]I need to remove /index/ from the first and third URL, and /index/profile/ from the second one.All comments & suggestions are welcomed.
.htaccess rewrite rules for multiple parameters
By default, child htaccess files donotinheritparent rules.You'll need to add this line in each child htaccess filesRewriteOptions Inheritor, even better (if you want parent rules to be applied before child ones)RewriteOptions InheritBefore
So I have some crazy strangeness in mod_rewrites being ignored when child directories also have an htaccess file (regardless of whether the file has a conflicting rule or not).So example to redirect /index.html of a dir to / for canonical purposes...RewriteCond %{THE_REQUEST} /index\.html [NC] RewriteRule ^(.*?)index\.html$ /$1 [L,R=301,NC,NE] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1/index\.html -f [NC] RewriteRule ^(.+?)/?$ /$1/[R=301,L]So... if this is set in the root settings, then everything works. But once a child directory has an htaccess of its own (even without a conflicting rewrite) it just completely ignores.
Apache mod_rewrite craziness in inheritance
you can write .htaccess ruleRewriteEngine On RewriteRule ^Core/([^/]*)$ /Core/?page=$1 [L]Using this your page variable can be access in yourphpfile
Basically, I was wondering if I could take a url like:http://Localhost/Core/?page=signinand rewrite it tohttp://Localhost/Core/signin/like a "fake" folder.I'm using CSRF and when I submit the form it doesn't like PHP get variables in the url. I was hoping that if I were to use a "fake" folder it would change and then work..? Maybe not, any thoughts?
.htaccess Rewrite - PHP get variable to fake folder
You can use aRewriteRule:RewriteCond %{REMOTE_ADDR} !^111.222.333.444$ RewriteRule ^ - [R=404,L]However, this doesn't reallyhidethe fact a sub-domain exists. It returns a page not found, which is not the same thing. Presumably your subdomain still has a DNS entry, so it can be looked up.I would also question the need to do this,403exists for a reason and I can't see why not to return it. Whether or not you return a403or a404, the site still exists so I don't know what you're trying to achieve. No method would be enough to deter a determined hacker, and it's probably a safer method to deny an ip at server level rather than trying to obfuscate via http redirects.
I am using Apache 2.4 and I am blocking an access to a specific sub-domain for everyone except one IP address..htaccess:Require all denied Require ip 111.222.333.444This returns an "403 Forbidden" status code.How can I make it return "404 Not Found"?No-one from outside should know about the existence of this sub-domain. So, from external point of view, I would like to make it "invisible". Thus, everyone who goes to that domain, will receive 404 as if it does not exist.Is it possible?
Apache - Require all denied HTTP status code
You can usemod_rewritebased rules instead in your root .htaccess:RewriteEngine On RewriteCond %{THE_REQUEST} !/paypal_ipn [NC] RewriteCond %{REMOTE_ADDR} !^127\.0\.0\.1 RewriteRule ^ - [F]This will block all requests that are not:originating from localhost (127.0.0.1)for/paypal_ipn
I currently have my local.htaccesson a MAMP server set up to block all incoming traffic from outside my local system;<FilesMatch ".*"> Order deny,allow Deny from all Allow from 127.0.0.1 </FilesMatch>This works fine but I then use API's like PayPal that require access to your site for IPN's. Is it possible to keep the restriction on the rest of the site and allow outside access only to specific urls likehttps://example.com/paypal_ipn?I understand I can just switch the restriction off when using IPN's but that's not what I'm looking for. Many thanks.
.htaccess block outside access on local server except for certain URL's
You can use this code in yourDOCUMENT_ROOT/.htaccessfile:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule !^((admin|login)(/.*)?)?$ /#%{REQUEST_URI} [L,NC,NE,R=302]Also remember that web server doesn't URL part after#as that is resolved only on client side.RewriteCond %{REQUEST_FILENAME} !-fskips this rule for all files.Using!negates whole match inRewriteRulepattern((admin|login)(/.*)?)?matches anything that is/admin/or/login/OR emptry (landing page)If negation is true then this rule redirects it to/#%{REQUEST_URI}where%{REQUEST_URI}represents original URI.References:Apache mod_rewrite IntroductionApache mod_rewrite Technical Details
I want to redirect all incoming requests to another url if it doesn't contain # and admin. I need it for angular.js, but I have /admin with phpFor example:http://example.com/link-to-article->http://example.com/#/link-to-articlehttp://example.com/admin/* will not redirect
htaccess redirect if url doesn't contain some string
It is giving you internal server error (500) because withoutRewriteCondyour loop is infinitely looping.You can use this rule to prevent this:Options +ExecCGI AddHandler fcgid-script .fcgi RewriteEngine On RewriteRule ^((?!app\.fcgi/).*)$ /app.fcgi/$1 [L,NC](?!app\.fcgi/)is anegative lookaheadthat prevents this rewrite rule to execute if request is already/app.fcgi/.
Why does this work:Options +ExecCGI AddHandler fcgid-script .fcgi RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /app.fcgi/$1 [L]But if I remote theRewriteCondit doesnt work and I get an internal server error.Options +ExecCGI AddHandler fcgid-script .fcgi RewriteEngine On RewriteRule ^(.*)$ /app.fcgi/$1 [L]If I modify theRewriteConde.g. like this it doesnt work too.RewriteCond %{REQUEST_FILENAME} !-lI want to redirectallrequests to app.fcgi. I dont want the user to be able to access files directly.Thanks in advance!
htaccess RewriteRule without RewriteCond not working
You do not set this up. It's just that, if you serve different content from the same url based on properties of the client that connects to you (that's what dynamic serving is) you should also return this header, so that search engines know it's not the one true version of the page they are looking at, but just one of the User-Agent dependent versions.That way Google can crawl your site using multiple user agents, and cache and index each of them separately, so customers on various platforms are more likely to find the right information.You should use this header if you serve different content from the same url depending on the header. So first, you need to build a page that actually has different output based on the user agent, and when you have this, you can optimize it by setting the response header. You can do that by calling theheaderfunction in PHP:header('Vary: User-Agent');You can do it in htaccess too, but it's a good idea to only do it for those pages that actually have varying content. So in my opinion, it's just as easy to do it in PHP.
According toSearch Engine Landand many other sources, if you're designing "Dynamic Serving" mobile content for your site, you should set the HTTP header Vary: User-Agent.Is this done in the .htaccess file or somewhere else? This would be my first time doing this and I would greatly appreciate help and maybe even an example. After searching around, i have narrowed it down to either meta tags or htaccess, however, I could be wrong.Your help is very much appreciated. Thank you
Where and How to set Vary: User-Agent HTTP Header
Try:RewriteCond %{DOCUMENT_ROOT}/robots/%{HTTP_HOST}.txt -f RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L] RewriteRule ^robots\.txt$ robots/domain.txt [L]The condition in the first rule checks that the destination robots file exists, and if it does,robots.txtgets rewritten. Thus, the second rule only gets applied if the first rule doesn't.
I want to have domain-specific robots.txt and so far this works:RewriteRule ^robots\.txt$ robots/%{HTTP_HOST}.txt [L]But I would like to have a fallback so if the domain.txt file doesn't exist then go to default.txtAnd this doesn't really work out as it will redirect all non-existent filenames, plus I already have a !-f in a different rule: RewriteCond %{REQUEST_FILENAME} !-f RewriteRule robots/default.txt [L]So I would need to: 1-catch robots.txt requests 2-Send to robots/domain.txt if it exists 3-Else send to robots/default.txt
domain-specific robots file with htaccess rewrite robots.txt to example.com.txt or fallback to default.txt
The anser was a problem with our domain host WP Engine, who tricks spiders into ignoring pure numeric strings at the end of page URL's. Pertains specifically to:Googlebot (Google's spider)Slurp! (Yahoo's spider)BingBot (Bing's spider)Facebook OG/DebuggerFor example, the following URL:http://www.website.com/profile/12345Will be interpreted to these bots as:http://www.website.com/profileHowever, if the string is non-numeric the bots will recognize it. This is done for caching purposes. But again, this pertains only to WP Engine and a few other hosting providers.
So this is happening when I test my website using Facebook's Open Graph Object Debugger:It doesn't like the trailing numbers after the profile page. But I have both of these defined properly:<meta property="og:url" content="http://www.website.com/profile/139"> <link rel="canonical" href="http://www.website.com/profile/139">I've tried for hours and it just keeps redirecting to the homepage:Is there anything I can add to my.htaccessfile or PHP header to prevent this 301 redirect?May be related to the way Facebook/Google handle URL parameters:http://gohe.ro/1fpOA0N
How to get Facebook Debugger to read canonical URL?