Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
# Enable RewriteEngine to rewrite URL patterns
RewriteEngine On
# Every URI that not (! operator) ends with one of .php, .css, .js, .gif, .png, .jpg, .jpeg or .pdf
RewriteCond %{REQUEST_URI} !\.(php|css|js|gif|png|jpe?g|pdf)$
# Will be redirected to templates/index.php
RewriteRule (.*)$ templates/index.php [L]
# Sample
# /foo/bar.php -> /foo/bar.php
# /foo/bar.html -> templates/index.php | I have some troubles understanding how to dynamically put together simple one language website. I would really appreciate if somebody could explain me in baby language what every part of the code below means:RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(php|css|js|gif|png|jpe?g|pdf)$
RewriteRule (.*)$ templates/index.php [L]Thank you in advance! | Please, explain for total beginner this .htaccess file |
You can add it above any other rules in your htaccess file but the rewrite map definition must be in your vhost config, so in vhost:RewriteEngine On
RewriteMap lowercase int:tolowerAnd in the very top of your htaccess file:RewriteCond $1 [A-Z]
RewriteRule ^(.*)$ /${lowercase:$1} [R=301,L](note that you don't need to leading slash) | I have inherited a rather scary looking .htaccess file that is filled with previous rules. What I am trying to do is simply make every single URL lowercase for SEO reasons. Currently Google Webmasters is complaining about duplicate pages. eg: www.example.com/AbC1.php has the same content as www.example.com/abc1.php. To solve this I placed the following lines into my vhosts.conf#Make URL's lower case
RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond \$1 [A-Z]
RewriteRule ^/(.*)$ /\${lowercase:\$1} [R=301,L]But due to one of the many rules I have in my .htaccess file this rule isn't working. Can I add that above rule and ensure that it overrides any other rules? | Force lower case of URLs - Override previous rules |
Replace your code with this:ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+movie\.php\?name=([^\s&]+) [NC]
RewriteRule ^ movie/%1? [R=301,L]
RewriteRule ^movie/([^/]+)/?$ movie.php?name=$1 [L,QSA] | This is my .htaaccess code.RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ movie.php?name=$1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.in$
RewriteRule ^/?$ "http\:\/\/example\.in" [R=301,L]
ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag NoneI need clean url for my website.
I've referred lots of tutorials and forums and created the above code.
But not working.. Almost I'm fighting with code.
I dont understand the clean url concept clearly. Is there any codings I ve to write on my php page.<a href='movie.php?name=titanic'> Titanic </a>I've this link in my index.php file.I wantexample.in/movie/titanicwhile click the link Titanic.Also I want to get the value by $_[request].What exactly I've to do. Please dont make this question as duplicate, I've searched a lot and didn't got the concept clearly. Please help me out.Thanks | How to create clean url using .htaccess |
As thisdoc pagesays, you cannot use the<Directory>directive inside htaccess, but only inside server conf files.This is not a problem in your case anyway: you can store one.htaccessfile inside each directory, eg. create these files:Public/.htaccessOrder Deny, Allow
Allow from all
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Index.php/$1 [L]
</IfModule>/Config/.htaccessOrder Deny, Allow
Deny from all/Application/.htaccessOrder Deny, Allow
Deny from all/Storage/.htaccessOrder Deny, Allow
Deny from all | I am developing a tool and I'm stuck at this point: I want to define a set of rules for each directory, basically I want only 'Public' folder avaible, and to deny access to other folders.My directoy structure isuapi(root)/
Application
Config
Public/
Index.php
Storage
.htaccessand here is .htaccess file<Directory /Public>
Order Deny, Allow
Allow from all
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ Index.php/$1 [L]
</IfModule>
</Directory>
<Directory /Config>
Order Deny, Allow
Deny from all
</Directory>
<Directory /Application>
Order Deny, Allow
Deny from all
</Directory>
<Directory /Storage>
Order Deny, Allow
Deny from all
</Directory> | Apache - Deny access to all directories except public |
I know its late to answer but I giving it since it can be useful to someone :)#Remove php extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
#Remove html extension
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.htmlThis will remove both php and html extension from your files and works perfectly. | What lines should I add to remove both.htmland.phpextensions from my site?I use this for just the.htmlpart:RewriteEngine on
RewriteBase /
RewriteCond %{http://jobler.ro/} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) /$1.html [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.html\ HTTP
RewriteRule ^([^.]+)\.html$ http://jobler.ro/$1 [R=301,L]but I need for both file type extensions to be hidden from the same domain. | Apache .htaccess to hide both .php and .html extentions |
Have a look at yourAllowOverridedirectives. I had this problem too but the following config work for me:<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride AuthConfig Limit
Require all granted
</Directory>AllowOverride Allwill probably also work, just depends on how much you want to allow.Check out these two links for more info:https://drupal.org/node/10133http://httpd.apache.org/docs/2.2/howto/auth.html | I am trying to put authentication for accessing my document root directory in apache2...
Here's my config file<VirtualHost *:80>
ServerAdmin webmaster@localhost
AccessFileName .htaccess
DocumentRoot /home/user/workspace
<Directory />
Options FollowSymLinks
AllowOverride None.htaccess
</Directory>
<Directory /home/vishu/workspace>
Options Indexes FollowSymLinks MultiViews
AllowOverride AuthConfig
Order allow,deny
allow from all
</Directory>
......
......
</VirtualHost>here's my .htaccess file in /home/user/workspace folder:<FilesMatch >
.....
</FilesMatch>
AuthType Basic
AuthName "MY ZONE"
#AuthBasicProvider file
AuthUserFile /home/vishu/workspace/passwordfile
AuthGroupFile /dev/null
Require valid-user
.....
...Apache gives.htaccess:order not allowed hereerror and I am getting 500 error from browser. | .htaccess:order not allowed here |
You should probably be usingmod_proxyinstead ofmod_rewrite.ProxyPass /tomcat http://dev2.test.com:8000/
ProxyPassReverse /tomcat http://dev2.test.com:8000/EDIT :This configuration must be in httpd.conf. It may be in a VirtuaHost section or at the root of the file.You have to enable mod_proxy. This could be done usingLoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so | I have a few web applications available on my server on port 8080.As some of my users can't reach port 8080 due to their firewall, I'd like to set a redirection on my apache server. Il would like the following URLhttp://dev2.test.com/tomcat/somewebapp/restofthepathto display what is accessible athttp://dev2.test.com:8080/somewebapp/restofthepathOf course I don't want users typing the first address to see the second one.I added the following.htaccessfile in/var/www:RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(tomcat)
RewriteRule ^/tomcat/(.*)$ http://dev2.test.com:8080/$1 [P,QSA,L]But I get this error in/var/log/apache2/error.log:[Tue Oct 09 15:23:06 2012] [error] File does not exist: proxy:http://dev2.test.com:8080/tomcat/Could you please tell me what I should do ? | Transparent redirect to port 8080 |
To multiple<FilesMatch "(foo|bar|doo)\.php$">
Deny from all
</FilesMatch>or go for rewrite rules (RewriteEngine On)RewriteRule \.(psd|log)$ - [NC,F]To deny access to all files in the folders:rewriteRule ^www/php/login/pages - [NC,F]or simply place a `Deny from all' directly in that folder...Update 2015:Using Apache 2.4 or higher, the `Deny from all'would needs adjustment. | I'd like to deny multiple files through htaccess.<FilesMatch (profile|reg|register|..............|)\.php>
order allow,deny
deny from all
</FilesMatch>I have lots of files (6 folders with like 30 files each) that I want to deny access to, so using the method above by entering them one by one will take time.Could I deny access to all files in the folders like this?<Directory /www/php/login/pages>
Order Allow,Deny
</Directory> | Deny access to multiple files in htaccess |
For first part (first rewrite rule) tryRewriteCond %{REQUEST_URI} !portfolio/project
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_URI} /.*portfolio/.*$ [NC]
RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]I'm not sure why you useRewriteCond $1 !\.(gif|jpe?g|png)$ [NC]in second rewriterule.RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png)$ [NC]means you don't want to change portfolio to portfolio/project for urls ending with some of allowed image extension.[NC](case-insensitive) is used to skip JPG, GIF, PnG, etc extensions also | Inadvertently my htaccess script is changing image URLs so that any image with "portfolio/" in its URL path is adversely affected.Is there any way to exclude images from that particular rule?redirect 301 "/sitemap.xml" http://www.example.com/sitemap.php
RewriteEngine On
RewriteCond %{REQUEST_URI} !portfolio/project
RewriteCond %{REQUEST_URI} /.*portfolio/.*$ [NC]
RewriteRule ^(.*)portfolio(.*)$ /$1portfolio/project$2 [R=301,L]
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/sitemap.php
RewriteRule ^(.*)$ /index.php/$1 [L] | Excluding images from mod_rewrite rule |
The answer is simple:You cannot.http://httpd.apache.org/docs/current/mod/mod_rewrite.htmlThe only thing you can do is to group some parameters into one and then parse it later in your script.Of course, you can try splitting your pattern into 2 rules, so one rule matches 5 or 6 parameters, and then 2nd rule matches the rest (this will work because rules are executed one by one), but that will not always work (REALLY depends on actual rewrite rule, how complex it is) and requires good knowledge on what are you doing. | I'm having trouble spending more than nine parameters in. htaccess file with mod_rewrite apache, for example, if I pass the parameter $ 10 = "something" mod_rewrite passes the value of parameter $ 1. Is there any solution for this? | how to pass more than 9 parameters in the file. htaccess (mod_rewrite)? |
You need to create a virtualhost. Dayle Ress covers this in the first chapter in his Laravel book:https://web.archive.org/web/20121013083457/http://daylerees.com/2012/03/25/laravel-getting-started/ | I tried to makeLaravelworks on my environment (MAMP) but i'm stuck in this situation.Theindex.phpfile of Laravel is into a subfolder called "public", so if I want to test my application I need to access it with this urlhttp://localhost/laravel/public/but I want access withhttp://localhost/laravelI tried to set an htaccess with this rows but it doesn't work:<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1
</IfModule>I'm not sure that this htaccess can resolves this situation, I get a 404 generated by Lavarel. | Laravel (and generic) framework setting for "Public" folder |
Consider rewriting only non-existing paths, e.g. if file or directory exists - don't rewrite it.Wordpress uses this to rewrite their permalinks, I think it's pretty good example:# 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 WordPressAs you can see they have rewrite conditions to exclude existing files/directories. | my .htaccess file looks like:RewriteEngine On
RewriteRule ^([^/]*)$ index.php/?node=$1 [L]now when I include my css file with:<link href="sitewide.css" rel="stylesheet" type="text/css" />it doesn't work. The same goes for javascript. | .htaccess rewrite url breaks css/javascript/other files |
mod_rewrite won't automatically enforce redirecting browsers from rewritten URLs. The rule you have simply says "if someone asks for/testRewrite/, internally change it to/test.php". It does nothing to handle actual requests for/test.php, which is why when you try to accessmysite.com/test.php, it gives you/test.php.Now, the problem with mod_rewrite is if you simply add that rule:RewriteRule ^test.php$ /testRewrite/ [L,R=301]which will redirect the browser when it asks for/test.phpto/testRewrite/, the first rule will be applied after the browser redirects, and the URI gets rewritten to/test.php, then it goesback through the entire rewrite engineand the above rule gets applied again, thus redirecting the browser, thus the first rule rewrites to/test.php, and the above rule redirects again, etc. etc. You get a redirect loop. You have to add a condition to ensure the browser *actually requested/test.phpand that it's not a URI that's been churned through the rewrite engine:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /test\.php [NC]
RewriteRule ^test.php$ /testRewrite/ [L,R=301]This way, after the 301 redirect happens, this rule won't get applied again because the actual request will beGET /testRewrite/ HTTP/1.1, and the condition won't be met. | I have been pulling my hair trying to figure this out but nothing is working. I have a webpage atmysite.com/test.phpI want to do a simple URL rewrite and change it tomysite.com/testRewrite/The code to do implement this should be:Options +FollowSymLinks
RewriteEngine on
RewriteRule ^testRewrite/$ test.php [NC,L]For whatever reason it's just not working. When you go to the new URL -mysite.com/testRewrite/it works.However, if you type in the original URLmysite.com/test.phpit doesn't change the address to the new URL in the browser. | .htaccess RewriteRule works but the URL isn't changing in the address bar? |
Using a negative lookahead in the regular expression should work:RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/If you want the rest of the path to carry over with the redirect, use the backreference $1 as in:RedirectMatch 301 /a/b/(?!EXCLUDE.php) http://new.com/y/z/$1 | I would like to redirect as such...http://old.com/a/b/ -> http://new.com/y/z/
http://old.com/a/b/file.php -> http://new.com/y/z/
http://old.com/a/b/c/file.php -> http://new.com/y/z/
http://old.com/a/b/anything -> http://new.com/y/z/
http://old.com/a/b/EXCLUDE.php -> http://old.com/a/b/EXCLUDE.phpI currently have the following in httpd.conf and it redirects correctly:RedirectMatch 301 /a/b/(.*) http://new.com/y/z/I don't know how to exclude one file from being redirected.Basically I want all URL'sstarting with"old.com/a/b/" to go to a singe new URL, except I want a single URL to be ignored. | Redirect all but one file in a directory via httpd.conf / htaccess |
add one line in your .htaccess root:deny from all@QUESTION:if you want to retain access for yourself:allow from 192.168.1.1subsitute in your real IP for the one i gave in the example.so all together:deny from all
allow from YOUR_IP@QUESTION2:if you deny access to a directory, you are denying access to all of the nodes in that directory like the "pages". if you are saying you want to deny access to a folder in the same level directory as the pages, move the htaccess to inside of that folder (simplest)@EDIT:Open your .htacces fileLook for Options IndexesIf Options Indexes exists modify it to Options -Indexes or else addOptions -Indexesas a new lineThe directory browsing feature should be disable by nowhttp://www.techiecorner.com/106/how-to-disable-directory-browsing-using-htaccess-apache-web-server/ | in my server I have a series of folders. I would deny the access to all this folders. How can I do? What rule I have to use? | Disable Directory Browsing using htaccess |
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.cfm$ - [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.domain\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
#Change exists here:
RewriteRule ^(.*)$ /index.cfm?actualuri=$1 [L,QSA]
</IfModule>trycgi.query_stringnow. It should haveactualuri=/the/path/sent.Also, put the rewrite rules in the same order as put above. | I have an application I'm building in ColdFusion, whereby all requests will run through the index.cfm file.I have a .htaccess file that rewrites the URL. So, for example...if I write:http://domain.com/hello/goodbye/howdyThe actual request always uses index.cfm like so:http://domain.com/index.cfm/hello/goodbye/howdyThis all works great, but now I'm stuck with how I can grab everything that is in the URL. Not one of the CGI variables don't seem to output the "/hello/goodbye/howdy" part of the URL.I have tried cgi.path_info and cgi.query_string etc to no avail...they're just blank.I need to grab everything that comes after the domain name, and do stuff in CF with it. I know it's possible in JS, but I really need this on the server.Dumping the CGI scope shows me nothing useful in this regard:<cfdump var="#cgi#" />Here's my htaccess file for reference:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.cfm$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.cfm [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.domain\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>Thanks.EDIT:As an additional note, I've also tried the underlying Java methods like so:<cfdump var="#getPageContext().getRequest().getContextPath()#" />
<cfdump var="#getPageContext().getRequest().getRequestURL()#" />
<cfdump var="#getPageContext().getRequest().getQueryString()#" />To no success :( | How do I get the ENTIRE URL as seen in the browser without JS? |
Thanks LazyOne, this maybe working, but for me it often ended up in "mydomain.com/redirect:/app/webroot/index.php" which was really strange. But maybe this is due to the"{REQUEST_URI}"because I had to change myRewriteRule ^(.*)$ index.php?url=$1 [QSA,L]toRewriteRule ^(.*)$ index.php [QSA,L]due to strange problems with redirect (no idea what happend, CakePHP suddenly requestet a"Redirect:Controller"as also described herehttp://groups.google.com/group/croogo/browse_thread/thread/55539dabfd0191fd?pli=1- any idea about this?).It is nowworkingwith this code:RewriteCond %{HTTP_HOST} ^mydomain.com
RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://www.mydomain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L] | I know the topic "How to force HTTPS + WWW" is often discussed and solved, and in general it works for me.But as I now got a specific predefined .htaccess from CakePHP I do not know how to include it..htaccess for CakePHP:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]If I put the normal code for HTTPS/WWW Forcing in front or backwards to that code, it does not work properly because all requests are set to root directory and not to e.g. /contact.Normally I am using:RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteRule ^ https://www.mydomain.com%{REQUEST_URI} [R=301]But you can not just include that above...Could anybody please help meincludingHTTPS/WWW Forcing in the above .htaccess? | force SSL+WWW in CakePHP .htaccess |
If your hoster does not support.htaccessnor configuring the webserver with other methods, you would need to implement the whole HTTP stack into your own application to offer configuration of your own.That means sending the appropriate headers for the files in question next to the files itself. You would need to map those files onto commands your application (which is normally done with.htaccess+Mod_Rewriteas well).Shortly said, you would need to deliver everything by PHP scripts that set the headers in question. However this has the downside that PHP needs to process everything which will have a drawback on speed compared to static file delivery by the webserver. So I can not really suggest you to do it that way. It's much easier to just get a proper webhoster (or to upgrade your package) to get the features you're looking for before re-inventing the wheel. So getting some.htaccesssupport is probably the most easy way.As an alternative but somewhat similiar, you can consider to put the static files onto another host that provides the features you need (e.g. aCDN) and leave the core application on the current webhost, but I assume this only makes things more complicated than it does help you easily. | I was checking google page speed tool @http://pagespeed.googlelabs.comand my site point was 88. It suggest me to use Leverage browser caching for the site. I searched stackoverflow about it but all it was about htaccess, my hosting doesn't let me to use htaccess, how can I make it in PHP without htaccess?htaccess codes were<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch> | Leverage browser caching with php? |
Depends on yourRewriteBaseSo withRewriteBase /,^is relative to web root. In which case you would need^folder1/folder2/page.php | if I have an.htaccessfile on my site located atexample.com/folder1/folder2/.htaccessand I want to write a rule that effects a page atexample.com/folder1/folder2/page.phpWould i need to make the rule like:RewriteRule ^page\.php$ page/Or asRewriteRule ^folder1/folder2/page\.php$ page/Basically is the^(starts with) relative to the.htaccessfile or relative to the site root? | Is the ^ (starts with caret) relative to the .htaccess file or relative to the site root? |
This is completely impossible.Instead, consider using an image, or removing unused characters from the font. | My client ask me to use an especial font with @font-face on his website. But, that font is an asset to his organization, and he's afraid people would steal it. So, is there any way to make that .ttf file accesible by the browser, but prevent direct access (right now, you can read the url within the .css file, and download the font with any browser).I know there's no absolute solution, and the font would still be available for someone with the right skills set. But I just want to make it harder to steal for the non-experts.Any suggestions would be greatly appreciated! Thanks!How I solved this?Readingthis. Typekit's team did a GREAT job on this one. It's really impossible to prevent the robery, but you can make it hard. I did two things:With FontSquirrel Generator, I
removed all the desktop glyphs,
making the font unusable on a
desktop.Encode with Base64 all my TTF directly on my CSS
file. (ie. src:
url(data:font;base64,jdslajdsaljdlsajdsa))EOT fonts, for IE, can't be
converted to Base64. But, you can
load those vía a php script that
checks the referer, and prevent the
direct access.You still can reassemble the font having the base64, and yes, you can fake the referer and download the .EOT. But it would take someone with the right skills-set. People who steals fonts are regulary designer who doesn't know how to trick apache. | Preventing access to fonts with .htaccess |
You should be able to replace Wordpress'srel_canonicalaction function with your own function in which (when your conditions are meet) you create a canonical link appending the query string variable. The following should work, although you'll probably need to change the conditions to meet your needs.remove_action('wp_head', 'rel_canonical');
add_action('wp_head', 'my_rel_canonical');
function my_rel_canonical() {
if (is_page('item') && isset($_GET['pubID'])) {
global $post;
$link = get_permalink($post->ID) . '?pubID=' . absint($_GET['pubID']);
echo "<link rel='canonical' href='$link' />\n";
} else {
rel_canonical();
}
} | Does anyone know how to modify the Wordpress canonical links to add a custom URL parameter?I have a Wordpress site with a page that queries a separate (non-Wordpress) database. I passed the URL parameter "pubID" to display individual books and it is working OK.Example:http://www.uglyducklingpresse.org/catalog/browse/item/?pubID=63But the individual book pages are not showing up properly in Google - the ?pubID parameter is stripped out.I think maybe this is because all the item pages have the same auto-generated "canonical" URL link tag in the source - one with the "pubID" parameter stripped out.Example: link rel='canonical' href='http://www.uglyducklingpresse.org/catalog/browse/item/'Is there a way to perhaps edit .htaccess to add a custom URL parameter to Wordpress, so that the parameter is not stripped out by permalinks and the "canonical" links?Or maybe there's another solution ... Thank you for any ideas! | Wordpress auto-generated "canonical" links - how to add a custom URL parameter? |
You don’t need to specify the domain, you can simply use an absolute URL path:RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ /$1/ [L,R=301]That does also make a check for the URL scheme obsolete. | There are quite a few results foradd trailing slash .htaccesson Google, but all examples I found require the use of your domain name, as in this example:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]My problem is that a hard-coded domain name will not work on my local development machine. Is there a way to add trailing slashes without explicitly telling mod_rewrite the domain name? | Add Trailing Slash to URLs |
Put this before the last line.RewriteCond %{REQUEST_URI} !^/rss\.php$ | I have a .htaccess file which arranges that all requests go through index.php.
Now i would like to make an exception for rss.php. to go straight throuh rss.php.
How do I do this?This is how it looks like now:RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.phpThanks. | .htaccess file modification |
These are legacy access control directives. Either portOrder,allow, anddenyto "Require" or load the mod_access_compat module in your (non-htaccess) apache config. | The Apache version that I used in my local machine is 2.4, when I accessed the url of my application in the browser, I got this error./var/www/app/public/.htaccess: Invalid command 'Allow', perhaps misspelled or defined by a module not included in the server configurationThis is the content of my .htaccess file:SetEnvIf Request_URI ^/SOME_ENPOINT/ noauth=1
SetEnvIf Request_URI ^/auth/ noauth=1
AuthUserFile /var/www/app/.htpasswd
AuthType Basic
AuthName "APP Login"
Require valid-user
Allow from env=noauthI am thinking that I will remove this line of code below in .htaccess file.Allow from env=noauthI already enabled the mod_env module of my apache server.Is there way to solve this issue but using the environment variable noauth? Thanks :) | .htaccess: Invalid command 'Allow', perhaps misspelled or defined by a module not included in the server configuration |
You can define the HTTP Auth username and password like this:curl -u username:password http://...This way you don't have to disable the HTTP Auth while accessing it from a browser but can access it from your script.EDIT: If working with the PHP CURL object you can also define it as such:curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); | I have locked my development-environment with a .htaccess-password.While I'm now working on a script that uses a cURL-request to that htaccess-protected-folder, it doesn't work. When I delete the htaccess-protection it works fine.Is there a way to block UserAgents, like GoogleBot and other human requests, but allow cURL ? | .htaccess-Password is blocking cURL |
After 2 hours of searching for the solution it turned out to be extremely simple.All I had to do was change the order of my .htaccess file toRewriteEngine On
#Redirect to non-WWW
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*) https://example.com/$1 [QSA,L,R=301]
#if the request is not secure
RewriteCond %{HTTPS} off
#redirect to the secure version
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
# 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] | I am trying to force https and non-www on my laravel site. Here is my .htaccess file: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]
#if the request is not secure
RewriteCond %{HTTPS} off
#redirect to the secure version
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
#Redirect to non-WWW
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^(.*) https://example.com/$1 [QSA,L,R=301]Here are the current redirectsWorking redirectsexample.com => https://example.com (GOOD)
www.example.com => https://example.com (GOOD)
https://www.example.com => https://example.com (GOOD)Direct to the correct URL works finehttps://example.com => https://example.com (GOOD)
https://example.com/asdf => https://example.com/asdf (GOOD)NOT Working redirectsexample.com/asdf => https://example.com/index.php (BAD)
www.example.com/asdf => https://example.com/index.php (BAD)
https://www.example.com/asdf => https://example.com/index.php (BAD)I can't figure out why it's redirecting to the index.php file when I'm not on the main page. | Laravel 5.1 Force non-WWW and HTTPS Not Working |
The#is getting encoded as%23. Try using theNEflag in your rule:RewriteRule ^([0-9]+)/([0-9]+)$ /api/web/index.html#$1/$2 [R=301,NC,L,NE]theNEflag tells mod_rewrite not to encode the URI. | By using the following .htaccessRewriteEngine On
RewriteRule ^([0-9]+)/([0-9]+)$ /api/web/index.html#$1/$2 [R=301,NC,L]When user types the following URL at their browser.http://localhost:8080/1/2I'm expecting, Apache will perform internal redirection, and change the displayed URL at browser too (through R=301).http://localhost:8080/api/web/index.html#1/2Changing the displayed URL at browser is important. This is to ensureindex.html's JavaScript can parse the url correctly.However, what I really get ishttp://localhost:8082/api/web/index.html%231/2I will get Apache error.Apache false thought that, I wish to fetch a file named2located in directoryapi/web/index.html%231/Is there anything I can solve this through modifying.htaccessonly? | hashtag in apache .htaccess |
The "10" or the id, isn't part of the URL:example.com/account/blitzen12So you can't rewrite it into another URL, can't pull it out of thin air. You'll either need to just serve the page without an "id" (and pull it out of the database using the "name") or embed it in the URL without the query string, something like:example.com/account/10/blitzen12then you'd be able to rewrite it using:Options +FollowSymLinks
RewriteEngine On
RewriteRule ^account/([0-9]+)/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC] | this is my first time to try .htaccessthis is what i want.example.com/account/blitzen12 -> example.com/account/index.php?id=10&name=blitzen12i don't want to include the id in rewriting, is it possible?Note: id and name which is 10 and blitzen12 is retrive from the database.so far this is what I've tried but it didn't work.Options +FollowSymLinks
RewriteEngine On
RewriteRule ^account/(.*)$ ./account/index.php?page=account&id=$1&name=$2 [L,NC]html code.<a href="account/index.php?id=10&name=blitzen12">blitzen12</a>can anyone help me with this? Thank you. | .htaccess rewrite url with get parameter |
The content type is not set at request time, so far as I am aware. Thus, you would need to check if the browser is sending anAcceptheader, which describes to the server what kinds of data it will accept (and display) without downloading it. Most browsers do this. They send the following header string to the server (this is obtained from Chrome):Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Therefore, you would need to check theAcceptheader using a condition:RewriteCond %{HTTP:Accept} text/html [NC]
# Then, add your RewriteRules here ...This will check to see iftext/htmlis contained in theAcceptheader. | is it possible to redirect the user, based on the HTTP-Headercontent-type?For example:1)An Application is trying to loadlocalhost/res/123/var/abcand thecontent-typeis set to:application/jsonThe server should just return the JSON-Result to the application (which is implemented).2)If a normal web-browser is visiting the urllocalhost/res/123/var/abc, thecontent-typeis set to:text/htmlIn this case the server should redirect the browser to output a webview (e.g.index_web.html).Can i realize something like this without using PHP? | How to mod_rewrite based on http-header content-type |
This has not much to do with Wordpress and I am not an expert regarding.htaccess, but I believe that what your file is doing is not denying access to your directory by all.phpfiles, rather,denying access to all the.phpfiles inside the directory.The<Files>directive is used to add specific rules to specific files and, as far as I know, itcascades.Considering your comment, this should do the trick<Files *.php>
deny from all
</Files>
<Files "xml-sitemap-xsl.php">
Order Allow,Deny
Allow from all
</Files> | 1) My wp-content is hardened with a .htaccess file containing this code:<Files *.php>
deny from all
</Files>2) I want (need) to authorizexml-sitemap-xsl.phpOtherwise I get this error in my error log:client denied by server configuration: /home/user/mysite.net/wp-content/plugins/wordpress-seo/css/xml-sitemap-xsl.php, referer: http://mysite.net/sitemap_index.xml3) I think I should add the following code but I’m not sure if it’s the right code nor where to place it:<Files "xml-sitemap-xsl.php">
Allow from all
</Files>The thing I want to avoid is a conflict between the deny and allow commands.Thanks,P. | Allow a specific PHP file to access a hardened wp-content folder |
You can't put your CSS files or files to be served to browser in the application folder as it is protected for security reasons with a .htaccess file set to 'Deny from All' Your CSS, JS, image files etc, need to be outside of the application folder.Put your CSS file in a folder called 'css' in the 'www' folder so it is NOT inside 'application' or 'system'. Then make sure you use the following (notice the leading slash, denoting an absolute URL):href="/css/screen.css"Use this instead:# If your default controller is something other than
# "welcome" you should probably change this
RewriteCond $1 !^(index\.php|css)
RewriteRule ^(.*)$ /index.php/$1 [L] | This question has been asked several times, but I researched and still can't solve it. In one of my view file, I have (referencing to my css):link rel="stylesheet" type="text/css" href="/application/views/screen.css"The css file is in:- www
- application
- view
- css
- screen.css
- systemI also tried to setup the css in the same folder under-wwwand use it directly bylink rel="stylesheet" type="text/css" href="css/screen.css"My baseurlis set to""because I develop locally. Is this the issue? I'm Using wamp server.So what is the problem? Can anyone help? | Codeigniter + CSS not working well, possible baseurl |
Make sureLoadmodule mod_rewriteis uncommented.Make sure you have AllowOverride set appropriately for the vhost to allow .htaccess to do its thing.One example of a good directive is:<Directory "/some/absolute/path/htdocs">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>A good patter to follow for .htaccess for what you are trying to do is:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>Very close to what you are doing.Restart your apache server. | I'm getting kinda crazy over here because I already wasted two hours getting my clean URLs enabled for the laravel framework.I'm on a Mac and have a XAMPP setup. The Loadmodule mod_rewrite is commented out and php_info() says mod_rewrite module is loaded.My .htaccess file in the public folder of the laravel framework contains the code for cleans URLs (as stated on their website) but still, when I surf domain.com/account it gives me a 404.The laravel framework folder runs as a virtual host.What could it be, that is going wrong?!<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule> | htaccess for clean urls not being read by apache? |
i have found answer myselfOptions +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L] | I have a website that is hosted on Godaddy server. For SEO I have made all the rule free from .php extension. for url rewrite i am using.htaccessfile.htaccessfile is running fine on local server that is XAMPP, but on live server (godaddy server ) it is not working.I have no idea about.htaccessfile code.htaccessfile content isRewriteEngine On
Options +MultiViews | .htaccess file is not working on go daddy server |
You could create an intercept PHP script which would be responsible for handling all requests for images which are stored in a specific folder. Lets say all your images are located inside theimages/folder. You would simply need to create a rewrite rule which will redirect all requests for files inside that folder to a PHP script.RewriteRule images/(.+)\.(jpg|gif|png) images.php?image=$1.$2This way you would still retain the ability to use your images inside markup the way you did before.<img src="images/logo.png" />Do take into consideration that this approach might have a heavy impact on your system performance because all requests for image resources are now creating processing overhead due to the fact that PHP is invoked every time. | have a picture in my server named /images/pic.jpg . I want to track ip address of users who try to access that pic directly through url lik www.domain.com/images/pic.jpg. I can track ip address of manual user by:<?php $ipAddress = $_SERVER['REMOTE_ADDR']; ?> | How can i track hot linkers ip address using php |
Use this code in your.htaccessunderDOCUMENT_ROOT:Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is for a valid directory
RewriteCond %{REQUEST_FILENAME} -d
# If the request is for a valid file
RewriteCond %{REQUEST_FILENAME} -f
# If the request is for a valid link
RewriteCond %{REQUEST_FILENAME} -l
# do not do anything
RewriteRule ^ - [L]
# forward /blog/foo to blog.php/foo
RewriteRule ^blog/(.+)$ blog.php/$1 [L,NC]
# forward /john to user_page/profile.php?name=john
RewriteRule ^((?!blog/).+)$ user_page/profile.php?name=$1 [L,QSA,NC]Now insideprofile.phpyou can translate$_GET['name']to$uidby looking up user's name into a database table. | 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 questionOn my site, user profiles can be reached by the urlwww.example.com/user/profile.php?uid=3I want to make it easier for users to reach their profile by simply requesting forwww.example.com/usernameEach users has a username that cannot change. How can I do this?Here is my current .htaccess file
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
# finally this is your rewrite rule
RewriteRule ^blog/(.+)$ blog.php/$1 [L,NC]
RewriteRule ^(.+)$ user_page/profile.php?uid=$1 [L,QSA] | How do I achieve a url like www.example.com/username to redirect to www.example.com/user/profile.php?uid=10? [closed] |
Relatively easily.Match anything that does not begin with 'www.' and then redirect to the 'www.' version:RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] | Can anyone suggest how I get non www traffic to redirect to the www version of a website using the htaccess file - I know I have one created in my root directory but cannot be sure what to put.. any ideas | htaccess - get all non-www traffic redirected to the www |
This should work:RewriteCond %{HTTP_HOST} ^yourdomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com$
RewriteRule ^images\/?(.*)$ "http\:\/\/cdn\.yourdomain\.com\/$1" [R=301,L]However, please note that this is just a temporary solution!In order to get the max out of your CDN, you need manually point images to your CDN in order to save one HTTP for every image. | Recently I bought a CDN and set it up. In my site, the images are stored in a folder named 'images' and the Image urls are obviously linked in this manner. (*Ex : images/some_image.png*)Since I want to use the CDN right way, I need to rewrite the urls without having to manually change each and every image path.I tried an .htaccess code which was suggested for a similar problemRewriteEngine On
RewriteBase /
RewriteRule ^images/(.*)$ http://cdn.mydomain.com/$1 [L,R=301]But that didn't seem to work properly as all the images were linked improperly.So I would like to know the changes in this code. Any response would be appreciated. | CDN Related : Rewrite Image URLs automatically from .htaccess |
If you try to access a WordPress site using anything other than the site address set in the general settings tab (Go to the admin panel, and click on "Settings" then "General settings" in the left side menu) it will automatically redirect you. | A developer that I worked with told me that we had the non-www version of the site redirecting to the www version using a Wordpress database setting, not the .htaccess file. Does anybody know how to do this? | Redirect non-www on a Wordpress site without using .htaccess |
You cannot do it solely with .htaccess.You can do it with javascript (intercept the onclick event, construct the url string using the user entered data then redirect the page to this url), but this is not really reliable considering that javascript runs on the client side.My suggestion is to use PHP for this. The process is the same, but I'll use POST instead of GET as a method for the form. Before the page gets rendered, detect the$_POSTdata and construct the$urlusing it. Then redirect the page to that$url, usingheader("Location: ".$url);It will be best to useexit();after this, to make sure that the code below it will not get executed as the redirect is made. | Question regarding redirection using htaccess. On a GET search form submit I get the following url:http://www.example.com/search/?criteria=foo&filter=all&date=all&submit=search&page=1The above works fine. Then I have this rewrite rule in my htaccess:RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ search.php?criteria=$2&filter=$3&date=$4&submit=$1&page=$5 [L]The above also works fine. It allows me to use the following structure for my search results:http://www.example.com/search/foo/title/all/1/Now my question is when I click submit I would like it to use the new clearner url structure however it uses the messier one with the question marks and the equal signs. Now automatically I was thinking maybe I have to do a redirect in PHP however if I can do it with htaccess I would be happier as it means cleaner code.I also understand I can do this with JavaScript by intercepting the click and creating the seo friendly url but again if their is a way with htaccess I would prefer that.Hope you understand what im trying to achieve and many thanks for reading,fl3x7p.s im pretty new to htaccess so if you can explain/ guide etc that would be great | rewrite url when a form is submitted |
Do you have access to the apache error log itself? If this is a cPanel system and you have shell access, try viewing the log /usr/local/apache/logs/error_log - mod_security errors will appear there. Otherwise, you can look inside your control panel to see if it picks up any error messages.Even if mod_security is installed, you can still get a 500 error after putting SecFilterEngine in .htaccess if the keyword isn't allowed.I recommend contacting your web host to determine whether mod_security is the cause. If it is, you can ask them to create an exception. (I work for a web hosting company, and we're almost always happy to make mod_security exceptions for reasonable applications)If it's caused by mod_security and your web host won't create an exception, you either need to change hosting companies or find a different way to pass the url (base64 encoding might work for you) | I am having a problem like this:403 Forbidden on PHP page called with url encoded in a $_GET parameterI am getting "403 forbidden" error
When i pass a url as a GET variable like thishttp://script/test.php?url=https://stackoverflow.com/questions/askBut this is ok.http://script/test.php?url=stackoverflow.com/questions/askAnd even if i urlencode the url it still gives me a 403.Apache mod_fcgid/2.3.6 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 Server at ----- Port 80And I don't think this server has mod_security enabled, Because when I addSecFilterEngine Offin htaccess I get "500 Internal Server Error".Code snippet:$URL = mysql_real_escape_string($_GET['url']);
mysql_query("INSERT INTO `url` ...");So the question is, can I fix this without editing httpd.conf, because I don't have root privilege.
Thanks | 403 Forbidden when passing URL in GET variable |
RewriteCond %{REQUEST_URI} ^/(courses|foo|bar)$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]Should work wherecourses,fooandbarare directories that you want to add a trailing slash to. | I have this rule which works great and adds a trailing slash for every directory on my site.
How Can I add trailing slashes for only certain directories such /courses/ ? I don't want every directory / path to have a trailing slash.RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L] | .htaccess rewrite condition trailing slash only for specific directories |
Try this instead:RewriteRule ^forbid/(.*)$ - [F]Source:http://httpd.apache.org/docs/current/rewrite/flags.html#flag_f | How to force apache to redirect to a 403 error?I've tried:RewriteRule ^forbid/(.*)$ / [R=403,L]this caused 500 server error on the whole siteRewriteRule ^forbid/(.*)$ - [R=403,L]andRewriteRule ^forbid/(.*)$ [R=403,L]these simply don't workI have the following .htaccess file:RewriteEngine on
RewriteRule ^(config|backup)(.*)$ - [F] [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*)$ /admin/index.php?%{QUERY_STRING} [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !util
RewriteRule ^(.*)$ index.php?%{QUERY_STRING} [L,QSA]Please, help me! | 403 redirect doesn't work |
I doesn't sound like a great idea to parse all .js files as php. I would suggest using a .htaccess Rewrite directive to map the .js files in question, to your php script.RewriteRule /phpjs/.* /phpjs/js.phpThen addheader("Content-Type: text/javascript");to your php output. | Can someone explain what the difference is between AddType and AddHandler in htaccess files? I want to make the settings such that I can have a javascript file (.js) be run through the server as though it were a php file (application/x-httpd-php5) but then sent to the user's browser as a (text/javascript) file. How might i configure this? | What is the difference between AddHandler and AddType in htaccess files |
From your description, you're attempting to define aRewriteMapin a per-directory context via your.htaccessfile, but this isn't allowed. TheRewriteMapcan only be defined in a per-server context, either in the main server configuration or in a virtual server section.When you make requests to the server and the.htaccessfile is parsed, it encounters theRewriteMapdirective and issues an alert, which results in an 500 error being thrown. You'll likely see an entry in yourerror_logthat states "RewriteMap not allowed here". | I have been trying to do simple maping with RewriteMap directive in my htaccess, but for some reason i am getting error 500 everytime. my syntax is ..
Options +FollowSymLinksRewriteEngine on
RewriteBase /
RewriteMap name2id txt:nklist.txt
RewriteRule ^/name/(.*) /name_list_view.php?kid=${name2id:$1|NOTFOUND}in nklist.txt :1 David
2 Mark
3 Simonthe nklist.txt file is on the root of my website , same place where the htaccess is . As far as my debugging tells me that htaccess is not able to find the nklist.txt file, but any help would be thankful. | RewriteMap not working in mod-rewrite |
Try this:RewriteCond %{REQUEST_URI} !/noticeboard2\.php$
RewriteRule noticeboard noticeboard2.php?section=studios&subSection=studio-artists [L]This rule will rewrite any request that contains “noticeboard” in the URL path tonoticeboard2.phpin the same directory. | My client keeps editing the structure of the navigation in the website, which is leading to some mod_rewrite issues. How could i make this rule:RewriteRule ^studios/about-studios/artist-noticeboard noticeboard2.php?section=studios&subSection=studio-artists [L]to work if the url contains"noticeboard"? Like this:RewriteRule ^IF CONTAINS 'noticeboard' noticeboard2.php?section=studios&subSection=studio-artists [L]Any pointers welcome! | mod_rewrite rule: if URL contains a certain string |
I would put the language indicator at the start of the URL path like/en/…or/de/…. Then you can use a single script that checks the preferred language and redirects the request by prepending the language indicator:// negotiate-language.php
$availableLanguages = array('en', 'de');
if (!preg_match('~^/[a-z]{2}/~', $_SERVER['REQUEST_URI'])) {
$preferedLanguage = someFunctionToDeterminThePreferedLanguage();
if (in_array($preferedLanguage, $availableLanguages)) {
header('Location: http://example.com/'.$preferedLanguage.$_SERVER['REQUEST_URI']);
} else {
// language negotiation failed!
header($_SERVER['SERVER_PROTOCOL'].' 300 Multiple Choices', true, 300);
// send a document with a list of the available language representations of REQUEST_URI
}
exit;
}And the corresponding rules:RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)$ negotiate-language.php [L]
RewriteRule ^([a-z]{2})/([^/]+)$ $2_$1.php [L]Note that you need a propersomeFunctionToDeterminThePreferedLanguagefunction asAccept-Languageheader fieldis not a single value but a list of qualified values. So there might be more than just one value and the first value is not always the prefered value. | For language redirects we currently create folders in the web root containing an index.php file which checks theHTTP_ACCEPT_LANGUAGEserver variable. e.g. for the urlwww.example.com/press/in/var/www/site/press/index.php:<?php
if ($_SERVER["HTTP_ACCEPT_LANGUAGE"] == "en")
header("location: ../press_en.php");
else
header("location: ../press_de.php");
?>As the site has grown, we now have many such folders. I am trying to clean this up by moving the redirects to a single .htaccess file:RewriteEngine on
# Set the base path here
RewriteBase /path/to/site/
# The 'Accept-Language' header starts with 'en'
RewriteCond %{HTTP:Accept-Language} (^en) [NC]
# EN redirects
RewriteRule press(/?)$ press_en.php [L,R]
# DE redirects (for all languages not EN)
RewriteRule press(/?)$ press_de.php [L,R]The idea is the same as the php file, but it doesn't work. I have tried all the possible language settings / orders in Firefox preferences, and checked the headers are correct, but it always serves thepress_de.phpfile.What am I doing wrong, or is there a better way?(not including content negotiation / multiviews or anything that requires renaming files, this is not currently an option). | How to redirect based on Accept-Language with Apache / mod_rewrite |
From thedocumentation for mod_rewritethe pattern in RewriteRule matches against the part of the URL after the hostname and port, and before the query string so the query string is not included. That is why you don't get the other variables.To add a new query string parameterlanguage=xxwhilst preserving any existing query string you need to use the QSA flag (query string append). With this flag, just one rule based on your second case should be sufficient:RewriteRule ^([a-z]{2})/(.*) /$2?language=$1 [QSA] | I'm trying to rewrite an url from:http://domain.com/aa/whatever/whatever.phptohttp://domain.com/whatever/whatever.php?language=aaHowever, depending on existing $_GET variables, it either has to be ?language or &language.To do this, I use 2 regexes with the [L] flag:RewriteRule ^([a-z]{2})/(.*\.php\?.*) /$2&language=$1 [L]
RewriteRule ^([a-z]{2})/(.*) /$2?language=$1 [L]The second one works as expected... The first one however is never hit (it falls through to the second regex, which does hit), even though Regex Coach does show me that it should.edit:If just read that I need to use two backslashes to escape the question mark. If I do this, it does hit on the first regex but never find the other GET variables. | How do I preserve the existing query string in a mod_rewrite rule |
Try this rule:RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule .* $0.php [L] | I'm using mod rewrite to access my PHP files in the root directory of my website indirectly. Currently, I have something like this,RewriteRule ^(blog|about|page3|etc)$ /$1.php [L]But what I would like to use isRewriteRule ^(.*)$ /$1.php [L]So that I wouldn't have to update my .htaccess file whenever I wanna add a new page to my website. The problem with this however is that it affects my subdirectories too. Which makes CSS, javascript, images unaccessable because it redirects to "/dir/example.png.php".So what is the best solution here? | How do I make .htaccess work on the current directory and not subdirectories? |
RewriteEngine on
#redirect image hotlinks
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/?.*$ [NC]
RewriteCond %{REQUEST_URI} (.*)/Embedded/(.*jpg|.*gif|.*png)$ [NC]
RewriteRule ^(.*)$ %{HTTP_HOST}/%1/Shared/%2 [R=302,L]If the referrer is not blank, and the referrer is not equal to your own domain, and the request is for a resource in the /Embedded folder ending in jpg/gif/png, then rewrite the url to replace /Embedded with /SharedYou may want to change the[R=302]to a differentcodeto suit your needs. | I am trying to create a redirection when someone hotlinks images in one directory on my site. If someone hotlinks an image, I want to redirect them to a corresponding image (same file name) in a different directory.If someone hotlinks:www.mydomaoin.com/PlayImages/Basic/Embedded/{ImageName.gif}I want it to redirect to:www.mydomaoin.com/PlayImages/Basic/Shared/{ImageName.gif}Thoughts? | Apache .htaccess hotlinking redirect |
This works - I just tested it - Note I added an L to the end of the RewriteRule<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC,L]
#wp
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule> | I've added some extra functionality to my wordpress so that I can visit it with a variable and do extra stuff.The problem is, when I turn my ugly dynamic link into lovely permlink formatting in the .htaccess file, wordpress overrides it / ignores it. I've heard there's a way to do it, but the ways I try to do it based off what people have said still returns a 404 page regardless. I know that the file its pointing to works.2 ways ppl say works but I've had no joy with:1) insert the rules above the #BEGIN wordpress part
2) use add_rewrite_rule() wordpress function somewhereHas anybody had any success with these methods? or other methods?Here's what my .htaccess file looks like<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/ref/(.*)$ /index.php?ref=1&sid=$1 [NC]
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>In my themes function.php I've also tried adding:add_rewrite_rule('/ref/(.*)$', 'index.php?ref=1&sid=$matches[1]','top');With no success.I've also tried the solutions over @WordPress + mod_rewritewith no joy.Please help! :)any ideas? | How do you simply add new custom rewrites to the .htaccess of a wordpress without fail? |
Depending on your WP version, you can just use thePermalink redirect plugin-- should do the trick for you within WordPress and without mod_rewrite. However, as of WordPress 2.3, a lot of thisshould work automatically. At that point, the only thing you should have to do is redirect all your /blog/... requests to the route, which you can do via mod_rewrite roughly like this:RewriteRule ^blog(.*) $1 [QSA] | I currently have a blog set up with WordPress using URLs like so:www.domain.com/blog/?pid=384092817This was before I knew anything about anything. There's a significant amount of content there now and I want to change my URL structure to:www.domain.com/my-post-title-384092817Is there a way to set up my .htaccess and mod rewrite so when users go to the first url they get a 301 redirect to the second URL? I know to change my WordPress address (URL) setting from www.domain.com/blog to www.domain.com and my permalink setting to /%postname%-%post_id%, but how do I tell the old URLs to redirect to the new ones? | Changing WordPress URL structure while maintaing the proper 301 redirects with mod_rewrite |
try:php_value default_mimetype "text/css" | I'm working on a website that has a number of style sheets all of which need to be handled as PHP scripts server-side. My.htaccessfile looks something like this:<FilesMatch "\.(css)$">
ForceType application/x-httpd-php
</FilesMatch>This causes a small problem as the mime type of the http-response'sContent-Typefield is then set totext/htmlinstead oftext/css.Obviously I can fix this by addingheader('Content-Type: text/css')to all of my files but is there a better way?Can I do this from within the .htaccess file? None of the directives offered bymod_mimeormod_negotiationseem to be what I'm looking for. | Alternatives to PHP header function |
You can use this rule (you need to enablemod_rewrite)RewriteEngine On
RewriteCond %{TIME} >=20180730100000
RewriteCond %{TIME} <20180730110000
RewriteRule ^ /other_page [R,L]It will (temporarily) redirect to/other_pagebetween10:00:00 AMand10:59:59 AM(only on July 30)Explanation:%{TIME}value format isyyyymmddhhiisswhere:yyyy = year (4 digits)mm = month (2 digits)dd = day (2 digits)hh = hour (2 digits)ii = minutes (2 digits)ss = seconds (2 digits) | Is it possible to redirect on specific date/time?For Example ... what would be htaccess code for redirecting website on 30th July, 10 AM?UpdateHere is my current htaccess code, where my requirement (see above) will be includedRewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R,L]
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_URI} !(\.png|\.jpg)$
RewriteRule ^(.*)$ index.php?l=$1 [L]
RewriteCond %{THE_REQUEST} ^GET\ /(.+)\.html [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L] | Redirect on specific date/time with htaccess |
You can use<filesMatch>with regex pattern to test multiple files<filesMatch "(logo\.png|true\.p3|test\.jpg)">
Allow from all
Satisfy Any
</filesMatch>Documentation of theFilesMatchdirective ishere. | How can I combine multiple FilesMatch for specific files ?All the examples I found are for combining file extensionsIn my case I only want to allow 3 files :/img/logo.png
/sound/true.p3
/sound/false.mp3I tested that but it's not clean :<FilesMatch logo.png>
Allow from all
Satisfy Any
</FilesMatch>
<FilesMatch true.mp3>
Allow from all
Satisfy Any
</FilesMatch>
<FilesMatch false.mp3>
Allow from all
Satisfy Any
</FilesMatch> | Combine multiple FilesMatch (specific files) |
PHP has a basic web server feature. this server feature is what is used when you runphp artisan serve..htaccessis an Apache server featurenota PHP feature.PHP is not built to be a full blown web server so it doesn't have all the configuration options you would find on say Apache or Nginx | I'm still trying things with Laravel 5.4.
however runningphp artisan serveris not taking .htaccess file in /public into consideration, no matter what i edit in there it's still not processing it, the artisan serve runs at 127.0.0.1:8000--- i reached this issue cuz i was looking for one other thing which is:i wanted to have a route::get for the /images folder which is already located at /public, removing -d from htaccess conditions should solve this normally, thus making apache redirect requests even from folders to index.php,so while testing locally using php artisan serve i noticed that changes or even clearing the htaccess file does not change the behavior of laravel.Thank you for your time.[note]htaccess works if i run laravel from apache, or anything but php artisan serve. so my question is only about the serve command and it's behavior. | Laravel 5.4 artisan serve htaccess / and Routes::get for existing folders at /public |
www.domain/privacy-policy/"privacy-policy" is in the URL-path, not the query string, as you have used in your directive. Try something like the following instead, near the top of your.htaccessfile:RewriteEngine On
RewriteRule ^privacy-policy - [env=NOINDEXFOLLOW:true]
Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOWHowever, it would be preferable to use mod_setenvif instead of mod_rewrite to set the environment variable:SetEnvIf Request_URI "^/privacy-policy" NOINDEXFOLLOWUPDATE:Since you are using afront-controller(WordPress directives), theRewriteRuledirective to set the environment variable would need to go at the top of your.htaccessfile, before the WP directives. By positioning this directive after the WP directives it simply does not get processed. (TheSetEnvIfandHeaderdirectives can appear later in the file if you wish.)However, since you are using afront-controllerand rewriting all requests toindex.php, theNOINDEXFOLLOWvariable is not being set in the request you are seeing. After the rewrite toindex.phpApache changes this toREDIRECT_NOINDEXFOLLOW(REDIRECT_prefix) and this is what you need to check for in theHeaderdirective. So, in summary:SetEnvIf Request_URI "^/privacy-policy" NOINDEXFOLLOW
Header set X-Robots-Tag "noindex, follow" env=REDIRECT_NOINDEXFOLLOW(Not quite so intuitive.)And if you use theRewriteRuledirective instead to set theNOINDEXFOLLOWenvironment variable then this must appear at the start of the file. | I have a Privacy Policy page on my website www.domain/privacy-policy/ which I would like to noindex with the X Robots Tag. I have tried the following code but it does not match# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
## Redirect HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^privacy-policy - [env=NOINDEXFOLLOW:true]
Header set X-Robots-Tag "noindex, follow" env=NOINDEXFOLLOW
</IfModule>
# END WordPressQuestion has been edited to include full htaccess file for clarity. | X Robots Tag noindex specific page |
i need some help in understanding how just adding a forward slash at the end of destination URL made my data to get posted successfully?That is happening becausemyfolderon the destination site is areal directory. There is module calledmod_dirin Apache responsible for this behavior due to security reasons.Whenever a request comes for a real directorywithout a trailing slashthenmod_dirredirects to same URI plus a trailing slash using 301 status code.Once 301 redirect happens POST data gets lost.When you usedhttp://www.hissite.com/myfolder/to POST data thenmod_dirdidn't come into picture since your URI already has a trailing slash hence no redirect and no loss of POST data.This behavior can be changed using:DirectorySlash OffBut it is considered a potential security risk as it might reveal directory content. | I had a scenario in which a data on form inhttp://www.omsite.comto be posted on other website sayhttp://www.hissite.com/myfolderNow whenever the data was being posted, rather then getting posted or getting Status Code 200 I was getting 301 Status code for permanent redirect and hence data was not getting posted.Checking the destination URL I changed it fromhttp://www.hissite.com/myfoldertohttp://www.hissite.com/myfolder/, yes, I added only a slash after /myfolder and there I got the successful response.i need some help in understanding how just adding a forward slash at the end of destination URL made my data to get posted successfully?Note: Destination webpage was the subdomain of source webpage | Post Data is not recieved on destination URL |
You can do a condition statement just like what you stated.<If "%{REQUEST_URI} =~ /\.(gif|jpe?g|png|css|js)$/">
#put your header set stuff here
</If>https://httpd.apache.org/docs/2.4/expr.html#examples | I have a PHP Laravel application with a standard.htaccessfile as follows.<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]
</IfModule>If the requested URL maps to a static file, it is served, and otherwiseindex.phpis invoked. I need to add a set of headers for static files, which would kind of be the "else" of the last two conditions above. I need something like the below pseudo.if static file
Header set MyHeaderOne "something"
Header set MyHeaderTwo "something"
end ifI can add the headers just fine, but got stuck at doing so conditionally. I looked a bit atSetEnvIf, which may make it possible.So, how can I add some headers only for static files, i.e. if the requested file exists (e.g./images/example.jpg)? Thanks a lot in advance! | Conditionally set headers in Apache htaccess |
To remove trailing slash from query string you can use this rule:RewriteCond %{QUERY_STRING} ^(.+)/$
RewriteRule ^ %{REQUEST_URI}?%1 [R=301,L,NE]Make sure this is first rule in your .htaccess belowRewriteEngine Online. | I am having an issue trying to remove trailing slashes from the end of a query string in apache.I have the following rewrite rules in place right now to make the URL and Query String all lowercase:RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} ^[^A-Z]*[A-Z].* [OR]
RewriteCond %{QUERY_STRING} ^[^A-Z]*[A-Z].*
RewriteRule ^ ${lc:%{REQUEST_URI}}?${lc:%{QUERY_STRING}} [L,R=301]I have tried to add:RewriteCond %{QUERY_STRING} (.+)/$
RewriteRule ^ %1 [R=301,L]But it breaks the website. I have been searching for a way to do this but haven't come up with any solutions yet. I tried the answers fromthis postbut they didn't work.The reason I need to do this is because our application firewall looks for "ID" in the url and if there is any non alphanumeric character that comes after then it blocks the request. The firewall is implemented after the Apache request hits the server.Hoping someone with more experience with Apache Rewrite rules can help me out. Thanks in advance. | Remove trailing slashes from Query String Apache |
One way to create nice routing is to let everything go to oneindex.phpand control the flow there. It has multiple advantages like being able to query the database and then decide what page to load. That can influence SEO nicely. | I have the following situations on my server:/->
news->
.htaccess
index.php
post.php
...And the following rules in my .htaccess:RewriteRule ^(.*)/admin post.php?slug=$1&admin_mode=true [NC,QSA,L]
RewriteRule ^(.*)$ post.php?slug=$1 [NC,QSA,L]Now I need my URLs to be the following:If requested www.mydomain.com/news/ -> it should get the index.php
fileIf requested www.mydomain.com/friendly-title-of-my-article -> it
should get the post.php file with the query string as indicated in my .htaccess.Currently I get correctly the post.php with the query string, but when I go to www.mydomain.com/news/ , it's requesting the post.php file.Please help. Thanks | htaccess check if empty query string |
You can't match against the query string inside a rewrite rule or a redirect directive. You need to match against the%{QUERY_STRING}variable. Try:RewriteCond %{QUERY_STRING} (^|&)w=[0-9]+(&|$)
RewriteRule ^(.*)$ http://sub.domain.com/$1 [L,R=301]Note that the query string gets automatically appended to the end of the rule's destination. | I have a client with an old website without 'pretty' URLs. So currently it looks like this:http://www.domain.com/?w=42&a=5&b=3The parameter values are numbers only.Now they want to move the old site to a subdomain and main (www) domain would be home to a new website (WP with SEO friendly URLs).Now what I would like to do is redirect all requests that come to the/?w=<num>(and ONLY those) tosub.domain.com/?w=<num>, so that existing links (mostly from Google) get redirected to the subdomain page, while the new page works serving new content thorough pretty URLs.I tried this:# This works, but redirects the entire www.domain.com
# to sub.domain.com no mather what
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://sub.domain.com/$1 [R=301,L]
# But this DOESN'T work
RewriteRule ^/?w(.*) http://sub.domain.com/?w$1 [R=301,L]
# Also tried to redirect 'by hand', but DIDN'T work either
Redirect 301 /?w=42 http://sub.domain.com/?w=42What am I doing wrong? I searched high and low but always end up with this kind of suggestions. Or maybe I'm just searching for wrong keywords ...Thank you! | .htaccess redirect only if GET parameter exists |
Replace your current code by this oneRewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]Note: maybe you'll have to clear your browser's cache to see it working forhttp://example.com/somepage | Currently my htaccess code is#add www
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
#send all traffic to https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}This works when following urls are entered1. https://example.com -> https://www.example.com
2. http://example.com -> https://www.example.com
3. http://www.example.com -> https://www.example.com
4. https://example.com -> https://www.example.com
5. https://example.com/somepage -> https://www.example.com/somepage
6. http://www.example.com/somepage -> https://www.example.com/somepageBut it doesn't work when both https and www is not present while trying to access some page, instead it redirect to strange url7. http://example.com/somepage -> https://www.example.com/https://example.com/somepage | HTACCESS add WWW with HTTPS redirect |
Assuming that I've understood the question correctly, your answer ishere. Morereference.<?php
$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
?> | I have a password protected directory with htaccess and htpasswd.My.htpasswdfile looks like this:user1:passwordstring
user2:passwordstring
user3:passwordstringWhen any of the user login successfully into the directory is there anyway I can get that user's name using php? | how to get logged in user's name from .htpasswd? |
Please remove yourErrorDocumentrule and replace it with following code :RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ error.php [L]A suggestion by the way: You should put a[L]behindRewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}, so that no other rule will override the HTTPS-enforcement.Your.htaccesswill then look like this:Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteRule index.html$ index.php [L]
RewriteRule service.html$ service.php [L]
RewriteRule ^([^/]*)\.html$ about.php?pid=$1 [L]
RewriteRule ^cont/([^/]*)\.html$ contact-inner.php?tid=$1 [L]
RewriteRule ^contact/([^/]*)/([^/]*)\.html$ contact-page.php?tid=$1&ona=$2 [L]
RewriteRule ^about/([^/]*)\.html$ about-inner.php?oid=$1 [L]
RewriteRule ^service/([^/]*)/([^/]*)\.html$ service-page.php?oid=$1&ona=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ error.php [L]
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 117.202.102.84
deny from 58.68.25.210
deny from 91.200.13.112
deny from 86.128.130.170
deny from 91.200.13.7
deny from 173.208.206.90 | I created custom 404 error page called error.php, now I want to display the error.php content in user entered url.like this link:http://www.youtube.com/asdfasfsdThis is myhtaccesscode:ErrorDocument 404 https ://localhost/path/error.phpI want to show the error.php content in same URL without redirect to error.php pageif user typed invalid url (for example:https ://localhost/path/nnn.php)current result:redirecting to error.phpexpected result:display error.php content in https
://localhost/path/nnn.phpMy fullhtaccesscode:Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule index.html$ index.php [L]
RewriteRule service.html$ service.php [L]
RewriteRule ^([^/]*)\.html$ about.php?pid=$1 [L]
RewriteRule ^cont/([^/]*)\.html$ contact-inner.php?tid=$1 [L]
RewriteRule ^contact/([^/]*)/([^/]*)\.html$ contact-page.php?tid=$1&ona=$2 [L]
RewriteRule ^about/([^/]*)\.html$ about-inner.php?oid=$1 [L]
RewriteRule ^service/([^/]*)/([^/]*)\.html$ service-page.php?oid=$1&ona=$2 [L]
ErrorDocument 404 https://localhost/ezhil/path/public_html/error.php
<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from 117.202.102.84
deny from 58.68.25.210
deny from 91.200.13.112
deny from 86.128.130.170
deny from 91.200.13.7
deny from 173.208.206.90 | display custom 404 error page without redirection in PHP |
UPDATE: This answer may no longer work in newer browsers.Because phishing people use @ and : marks in URL to hide URLs. For
example in a URL likewww.facebook.com:[email protected]user will oversee @notfacebook.com part and enter login details to a phishing webpage without noticing the latter. So now either this method will not simply work or
either you will see a warning saying this URL maybe a phishing site. So even if it's a private webpage where only you have access to it browser will try its protective mechanisms.Found the answer!Can pass it from the URL itself!http://username:[email protected]and the content of the url gets hidden after as well
Also global compatible as I know! | I have a webpage which refreshes every 5 minutes with client details. I have added a username password to it through the basic and standard htaccess and a htpassword file type login system it since part of the file contains company data.But I need this same webpage to be opened at my work PC which is a secured PC connected to a display screen to display same.On a power cut or a internet disconnection the PC has a startup file with a shortcut to this webpage so it appears automatically BUT stops from the 401 Authorization login form. So no go until I fill the details.Is there a way I can keep a file with a php or a javascript or jquery code so it can feed the username password to that and open the webpage (even as a iframe)?No need to worry about the safety of the file - the PC is locked in a cabinet with only a small set of holes for ventilation and for the display cable coming out to the monitor and another small hole to reach the power button.If you know to do this on android let me know as well.Found the answer!! See my post below! | Auto authenticate a htaccess (401) username password login |
This is most likely due to enabling ofMultiViewswhich runs beforemod_rewriteand rewrites/page to /page.php.Add this line on top of your .htaccess to disable it:Options -MultiViews | I have a simple rewrite that changeshttp://website.com/page.php?id=1intohttp://website.com/page/1using the following rewriteRewriteRule ^page/(\d+)/?$ /page.php?id=$1 [L]The rewrite works, it displays the page (i don't get a 404), but it doesn't appear to be passing through the id from the URL.To test this I basically echoed the $_GET['id'] and nothing was returned.Does anyone know why I might be going wrong?Many thanks | URL Rewrite - $_GET variable not passing through |
Can you try:Order deny,allow
Deny from all
<Files ~ "\.(xml|css|jpe?g|png|gif|js|pdf)$">
Allow from all
</Files>
<Files ~ "baz\.php$">
Allow from all
</Files> | My initial .htaccess allows access only to non-php files in a directory:Order deny,allow
Deny from all
<Files ~ ".(xml|css|jpe?g|png|gif|js|pdf)$">
Allow from all
</Files>I want to allow access now to one specific php file (relative path from .htaccess foo/bar/baz.php)Tried adding<Files foo/bar/baz.php>
order deny,allow
Allow from all
</Files>also tried<Files ~ "(baz)$">
order deny,allow
Allow from all
</Files>How do I add access for this one file? | htaccess allow access to one PHP file |
The FallbackResource directive wasn't introduced until 2.2.16 as describedhere. Upgrading Apache should solve your problem. | ContextI have Apache 2.2.15 configured for mass virtual hosting as follows:<VirtualHost *:80>
# ...irrelevant lines omitted
VirtualDocumentRoot /srv/www/%-3+
ServerName example.com
ServerAlias localhost
</VirtualHost>mkdir /srv/www/foomakesfoo.example.comavailable.ProblemHTTP 500 from all offoo.example.comwhen a.htaccesscontainingonlyaFallbackResourcedirective is in the vhost document root. Commenting outFallbackResourceremoves the error, but I want to useFallbackResource.Stuff triedI confirmed the relevant module was loaded usinghttpd -M | grep dir_module. Oddly enough I still seeInvalid command 'FallbackResource', perhaps misspelled or defined by a module not included in the server configurationin the error log.The filesystem is as simple as possible. There is only a "Hello, World"index.phpand a.htaccess. Yes, permissions are fine./srv/www
foo
index.php <- 775, owned by apache
.htaccess <- 664, owned by apacheI tried each of the following in.htaccess:FallbackResource index.phpFallbackResource /index.phpFallbackResource foo/index.phpFallbackResource /foo/index.phpAlso tried<Directory /srv/www/foo>even though that would not have worked anyway.New stuff tried given comments belowAllowOverride IndexesraisesAllowOverride not allowed herewhen entered into<VirtualHost>container.ConfirmedLoadModule dir_module modules/mod_dir.sois inhttpd.confAnything stupid/obvious I am missing? | HTTP 500 using FallbackResource and mass vhost config |
This should work in one .htaccess file atprimary.comroot directory:Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.primary\.com [NC]
RewriteRule ^apples/(.*) http://www.secondary.com/$1 [R=301,NC,L] | I am trying to create a permanent htaccess redirect (301) from all files in one directory in one domain, to another domain as follows:Redirect all files in the following directory:http://www.primary.com/apples/*To:http://www.secondary.comI am not very experienced with htaccess and was wondering if someone can assist me in creating this redirect?Many thanks in advance! | Htaccess redirect all files from subdirectory in one domain to another domain |
I have the same trouble.
I use Apache config alias, like:<VirtualHost *:80>
...
Alias /project "/Users/foo/Sites/project"
...
</VirtualHost>To solve, I use "RewriteBase" directive on .htaccess, example:RewriteEngine on
RewriteBase /project # <---- Modify here! and remove this comment.
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.phpSource:http://www.yiiframework.com/wiki/214/url-hide-index-php/#c9725 | I am working withYii FrameworkonApache/2.2.15 (CentOS) Server.Following line is uncommented in/etc/httpd/conf/httpd.confLoadModule rewrite_module modules/mod_rewrite.soI can seemod_rewriteunderLoaded Modulewhen I do following<?php phpinfo(); ?>Yii Project Structure:/var/www/test/
/var/www/test/index.php
/var/www/test/.htaccess.htaccess contentRewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.phpIt works fine when I do:http://10.20.30.40/test/index.php/testcontroller/testactionBut when I do:http://10.20.30.40/test/testcontroller/testactionIt shows following error:Not Found
The requested URL /var/www/test/index.php was not found on this server.Any idea? | How to remove index.php from Yii URLs in Apache/Centos? |
Try to put this in your.htaccess:<FilesMatch "php.ini">
Order allow,deny
Deny from all
</FilesMatch>It denies access to anyone trying to reachphp.ini.Edit: Allow and Order are deprecated in Apache 2.4. You should useRequire all deniedinstead.<FilesMatch "php.ini">
Require all denied
</FilesMatch> | Because we have some custom configuration in our php.ini file we apparently have to store it in the root dir of our site & hence any user would be able to see it.How I can I block people accessing it via their browser for example? | Denying user access to php.ini file with .htaccess |
You may try this:RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/? [NC]
RewriteRule .* index.php?key1=%1&key2=%2&key3=%3&key4=%4 [L]Maps silentlyhttp://localhost/val1/up tohttp://localhost/val1/val2/val3/val4To:http://localhost/index.php?key1=val1up tohttp://localhost/index.php?key1=val1&key2=val2&key3=val3&key4=val4Not incomingvalNvalues are empty in the substitution URL.index.phpis considered a fixed string.For permanent redirection, replace [L] with[R=301,L],Maximum number of parameters = 4. | I'm pretty new to this mod_rewrite business but I'd like to have a rule that allows me to accomplish the following:localhost/module_name/ -> localhost/index.php?module=module_name
localhost/module_name/module_action -> localhost/index.php?module=module_name&action=module_action
localhost/module_name/module_action/parm1 -> localhost/index.php?module=module_name&action=module_action&parm_1=parm1
localhost/module_name/module_action/parm1/parm2 -> localhost/index.php?module=module_name&action=module_action&parm_1=parm1&parm_2=parm2and so on. I managed to get module_name and module_action to work, but I can't figure out how get it to work with only a module or with multiple parameters. This is what I currently have:RewriteEngine on
RewriteRule ([a-zA-Z]+)/([a-zA-Z]+) index.php?module=$1&action=$2
RewriteRule ([a-zA-Z]+)/([a-zA-Z]+)/([a-zA-Z]+)$ index.php?module=$1&action=$2&parm=$3The first rule seems to work but it breaks apart on the second one.Any help would be really appreciated. | .htaccess mod_rewrite url with multiple optional parameters |
Nope, domains and subdomains are always lowercase. The DNS system is always case insensitive.https://www.rfc-editor.org/rfc/rfc4343 | Say I have the domain mydomain.com, and what I want to do is force the browser to show MyDomain.com in the URL bar. I have the following htaccess:# force all to MyDomain.com
RewriteCond %{HTTP_HOST} !^www.MyDomain
RewriteRule (.*) http://www.MyDomain.com/$1 [R=301,L]But it doesn't work. Are there any tricks/hacks that can be done to make the browser show a URL that isn't all lowercase? Or is this just not possible to do? | how can i force URLs to be case sensitive |
The digest authentication method uses a different type of password file. You can't use a password file generated for BASIC to use with DIGEST. You need to use thehtdigestcommand(or some equivalent online digest file generator) to create the password file. | I'd like to protect a folder by .htaccess. The following doesn't work. It displays the login dialog in a browser, but it looks as if the username and password don't match. When I changed the method to Basic, it worked fine.AuthUserFile /home/pass/.htpasswd
AuthName "Login"
AuthType Digest
Require valid-user | htaccess Digest authentication |
The recommended action would be to disable the public display of all PHP errors when you are in production mode.To do that, edit yourphp.inifile and setdisplay_errorsto0. You can still set theerror_reportinglevel to something suitable and all errors will be logged to theerror_logfile, but the actual errors themselves are not visible to the end user.Otherwise, there is no way to modify PHP's built in error messages to hide the path. Doing so would render the error message much less helpful.Seedisplay_errorsanderror_reportingPHP directives.EDIT: In the case of the exact error message in your question, you could handle the error (try/catch) and then display a more friendly error that helps you but also doesn't expose your path. The reason it is displaying like that is because an exception that was thrown was uncaught. | I have question. I have some app on facebook and getting this errorFatal error: Uncaught OAuthException: An active access token must be used to query
information about the current user. thrown in
/home/xxx/public_html/domain/lib/base_facebook.php on line 1024but no matter at this time.. the matter is that, is it possible to change/hide this "xxx" name? you understand? for example, instead this I would have/public_html/domain/...OR completely hide the path ??thanks in advance =) | how to change/hide server directory name? |
You need to addQSA(query string append) to your flags.RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,PT,L]Then your$_GETwill contain the correct values. | Hello fellow programmers,I'm using nice URLs the first time and I can't quite find out why I can't read my oAuth responses from my script.So this is my setup:.htaccessRewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]I have a script that uses googles oAuth system to log in a user. This script sends the user to the google api page where they can allow my website to read their email adress and then send the user right back to my site with lots of $_GET variables.I tell google to send it tohttp://mywebsite/login/google/responseand it does that..The problem is that google sends the result in the normal GET format like this:http://mywebsite/login/google/response/?openid.ns=http%3A%2F%2Fspecs.openid.ne[..]and my script can't read it..Is there any way to read $_GET variables when they mix with nice URLs? | How to read $_GET variables with (mod rewrite powered) nice URLs |
In a.htaccessfile in your document root...Options -IndexesSeehttp://httpd.apache.org/docs/2.2/mod/core.html#options | On my server, I've created a folder that doesn't have an index.php or index.html.folder1/test.php
folder1/sample.php
folder1/hello.phpWhen I tried to visit that folder, it shows all the files in there.That is my concern, it should not show the files in my folder because it is prone to hacking. It should display a page like a 403 Forbidden. I don't want to used an index.php just to redirect them to somewhere.I heard that this involves .htaccess and this is a smart thing to do.Kindly teach me how to do it. | .htaccess don't allow user to view my folder files that don't have index.php |
No you can't do this, as anything after the # is a fragment identifier and therefore not sent to the server.See the RFC on URIs here:https://www.rfc-editor.org/rfc/rfc3986#section-3.5 | I'm usingjquery addressand everything is working great except for one small issue inside my .htaccess file. I'd like to redirect one of my urls that includes a hashmark to another URL.Here is my current setup using redirect (that works):Options +FollowSymLinks
RewriteEngine on
RewriteRule view_profile=(.*)$ view_profile.php?id=$1If a user logs in at any point this URL doesn't work because my jquery address looks like this:http://localhost/#view_profile=5If I add the leading hash as part of my rewriterule it breaks. Does anyone know if it's possible to use a leading hashmark as part of the URL? | Can I use a hashmark in .htaccess URL? |
Store the uploaded images in a non web-accessible folder, then
Use a rewrite rule to forward requests to php; Something like:RewriteRule ^images/([^/]+) /image.php?img=$1 [NC]Do your validations in the php and if ok forward the image from the non-readable folder via php; something likeheader('Content-type: '.$mime);
header('Content-length: '.filesize($filename));
$file = @ fopen($filename, 'rb');
if ($file) {
fpassthru($file);
exit;
} | I'm working on an app where users can create an account and upload images, which get stored in a directory and can then be displayed within the application itself or in a publicly visible part of the app. Now I'd really like to protect the images to ONLY allow access to these images in the event that certain conditions are met, i.e, a session is set or the permissions in the db for the image are set to public, to name a few.So, what I'd need is that whenever an image from that directory is loaded, the htaccess file passes the image name onto a php file in that directory, which runs whatever checks it has to, and if it returns true, htaccess can proceed with spitting out the image (whether it's in an tag or just entered in the address bar of the browser).I've trolled through many posts but haven't found anything. I can't imagine it's not possible, so anyone who can offer guidance will be prayed for - and if you're local, well, other benefits may be in store! | Use htaccess to validate with php before granting access to a directory |
Have your .htaccess like this:Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^(biography)/?$ /#!/$1 [R,L,NE,NC]
RewriteCond $1 !^(images|system|files|themes|static|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]Remember you cannot have a condition to check for/#!in .htaccess because that part is handled in browsers only and not sent to web server. | Calling all .htaccess gurus. I need your help!I'm trying to force a rewrite to include #! in the urls.So basically I need.http://example.com/biographyTo be re-written tohttp://example.com/#!/biographyIf it will make any difference my rewrite rules so far areRewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond $1 !^(images|system|files|themes|static|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]I suck at this stuff so any help will be greatly appreciated.Additionally...I have this test doing what I need it to do in this htaccess tester.http://htaccess.madewithlove.be/But it won't work when I try it on my site...RewriteCond %{REQUEST_URI} !^/#!
RewriteRule ^(.*)$ /#!/$1 [L]No ideas as to why it won't work?Thanks,
Mark. | htaccess rewrite to include #! |
At the moment you're wondering how to convert your ugly URL (e.g./view.php?mode=prod&id=1234) into a pretty URL (e.g./products/product-title). Start looking at this the other way around.What you want is someone typing/products/product-titleto actually take them to the page that can be accessed by/view.php?mode=prod&id=1234.i.e. your rule could be as follows:RewriteRule ^products/([A-Za-z0-9-])/?$ /view.php?mode=prod&title=$1Then in view.php do a lookup based on thetitleto find theid. Then carry on as normal. | I'm trying to write an .htaccess file that will make my URLs more attractive to search engines. I know basically how to do this, but I'm wondering how I could do this dynamically.My URL generally looks like:view.php?mode=prod&id=1234What I'd like to do is take the id from the url, do a database query, then put the title returned from the DB into the url. something like:/products/This-is-the-product-titleI know that some people have accomplished this with phpbb forum URLs and topics, and i've tried to track the code down to where it replaces the actual URL with the new title string URL, but no luck.I know I can rewrite the URL with just the id like:RewriteRule ^view\.php?mode=prod&id=([0-9]+) /products/$1/Is there a way in PHP to overwrite the URL displayed? | Creating dynamic URLs in htaccess |
Here's a simple approach I sometimes use, which doesn't require any complication configuration.Whenever you modify a css or javascript file, simple add a dummy parameter to the markup. I typically use the current date and/or time. For example:<link type="text/css" rel="stylesheet" href="site.css?120911" />This forces the browser to download a new copy of the file when you need to update it, while still allowing you to maintain consistent file names behind the scenes. | I just searched the web but could not find a good answer to this:The Google page speed extension for FF told me to cache files on my website (PHP). Therefore I updated my.htaccess(in my beta-area of the website) in order to cache certain types of files:ExpiresActive On
ExpiresDefault A0
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>While coding in the beta area, I noticed that due to the cache control settings, I need to pressF5to get the lastest .css file for example. That's not bad for me... however what about the users?So can I tell the browser to re-download all files (only) when I update my site (or the file expires) and use the cache if not?It would be perfect if I could tell the browser: "Hey, all files before Update-time are old, please re-download them - however files after Update-time are ok, use the cache." | .htaccess: Cache Control, how can I handle Website Updates? |
TheRewriteRulefor promotions should still work as it's not 404ing.If the 404 handler is showing the page because it exists in the database then it should really be returning a200 OKstatus (overriding the 404 one), so you should not get any issues with browser toolbars.As for doing the rerouting you can do something like this:RewriteEngine On
RewriteCond %{REQUEST_URI} !^.*/(promotions|anotherone|somethingelse)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?p=$1 | So I just inherited a site. The first thing I want to do is build a nice little standard, easy-peezy, CMS that allows for creating a page with any URL (for example: whatever.html).Therefore, if user hits example.com/whatever.html, it should get any db info for whatever.html and display it. This is run of the mill stuff.My problem is that there are quite a few pages on the site (all listed in the .htaccess) that need to continue to be accessible. For instance, /Promotions is linked to promotions.php via .htaccess, and I need it to stay that way.Anyone know how I can construct the .htaccess file to allow specific rewrites to still work but to reroute all other requests through index.php?Currently, I just have .htaccess show a custom 404 page which in turn checks the db for the url and displays it if it exists. This is an easy solution, but I know that some people have weird browser toolbars (dumb or not, they exist :) ) that autoredirect 404s, and I'd hate to annoy my users with these toolbars by not allowing access to certain pages.Thanks so much for your help! | Using .htaccess to reroute all requests through index.php EXCEPT a certain set of requests |
You can read and write files with thefile system functions, for example:$data = <<<EOF
RewriteEngine on
RewriteRule …
EOF;
file_put_contents('.htaccess', $data);But it would be more flexible if you use one static rule that redirect the requests to your PHP file that then does the rest. | Can I make my .htaccess be generated with php?I would like to use php to dynamicly create my htaccess file from information from the database.It would save me the trouble of making a new .htaccess file whenever I change a bit of my code. | Can I make a dynamic .htaccess file? |
.htaccess is just a means of specifying Apache configuration directives on a per-directory basis. They allow numerous different kinds of password protection.If you are talking about HTTP Basic Authentication then the username and password are sent in cleartext with every request and are subject to sniffing (assuming you aren't using SSL).Aside from that, they are subject to the usual issues that any password based system suffers from.Using HTTP Basic Authentication doesn't grant any additional ability for users to upload and execute files. If they can do that already, then they can still do that. If they couldn't, they can't. | Are there any known flaws with htaccess protected pages?I know they are acceptable to brute force attacks as there is no limit to the amount of times someone can attempt to login. And if a user can uploaded and execute a file on the server, all bets are off...Are there any other .htaccess flaws? | How secure are .htaccess protected pages |
Try removing AddHandler, or changing it to:AddHandler fcgid-script .fcgi | I'm trying to setup django on a shared hosting provider. I followed the instructions onhttp://helpdesk.bluehost.com/index.php/kb/article/000531and almost have it working.The problem I'm facing now is that the traffic is properly routed throught the fcgi file, but the file itself shows up as plain text in the browser. If I run ./mysite.fcgi in the ssh shell, I do get the default django welcome page.my .htaccess is:AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]and mysite.fcgi:#!/usr/bin/python2.6
import sys, os
os.environ['DJANGO_SETTINGS_MODULE'] = "icm.settings"
from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")thanks. | FCGI htaccess handler |
You can use eithermod_rewrite:RewriteEngine on
RewriteRule ^v1(/.*)?$ /v2$1 [L,R=301]Ormod_alias:Redirect permanent /v1 /v2 | I moved my website from the /v1/etc... directory to the /v2/etc... directory and would like to make a permanent redirect in htaccess. Can someone help me? | htaccess rewrite directory |
You could try the<IfModule>Apache directive to distinguish your development machine from the production machine.E.g. the following would work if you're running PHP as an Apache module, and your ISP runs it as CGI:<IfModule !mod_php5.c>
AddType x-mapp-php5 .php
</IfModule>You could also check for the existence of a PHP4 module.Or you could pass a startup parameter to Apache on your development machine and check for that using<IfDefine>. | My ISP requires me to put the following in my .htaccess files:AddType x-mapp-php5 .phpBut that breaks my development machine.I don't really understand what that directive is for, but I'm sick of commenting it out for dev, and uncommenting it whenever I need to upload a new version.Is there some way of supporting it in dev? | How to support "AddType x-mapp-php5 .php" on my development machine |
I'm guessing that the problem is that the URL is being rewritten by the first rule, and then rewritten again by the second.The solution to that is to add the "last" flag to the first rule, like this:RewriteRule ^/src/pub/(.*)$ /$1 [R,L] | Given my current .htaccess file, how would I modify it to check for an additional URL path like '/src/pub/' and rewrite it to '/' without affecting the current rewrite?Here's the original .htaccess file:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]and here's my recent attempt (which doesn't work):RewriteEngine on
RewriteRule ^/src/pub/(.*)$ /$1 [R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]Edit:Here are some examples of what I want to accomplish:New Additional Rule:From: http://www.mysite.com/src/pub/validfile.php
To: http://www.mysite.com/validfile.php
From: http://www.mysite.com/src/pub/user/detail/testuser
To: http://www.mysite.com/user/detail/testuserExisting Rule (already working):From: http://www.mysite.com/user/detail/testuser
To: http://www.mysite.com/index.php?route=user/detail/testuser | How do I make mod_rewrite suppress processing more rules? |
DotsIf a file or directory path portion has a . as the first character,
then it will not match any glob pattern unless that pattern's
corresponding path part also has a . as its first character.For example, the patterna/.*/cwould match the file ata/.b/c.
However the patterna/*/cwould not, because*does not start with a
dot character. You can make glob treat dots as normal characters by
setting dot:true in the options.Set the option:gulp.src('...…….', { dot: true })so that the dot is treated like any other character. You should be able to use your original gulp.src then.Fromnode-glob documentation | In a gulp task, I try to copy files in a build folder.gulp.task( addon, function() {
var a_addon_function = addon.split("_") ;
var addon_dirname = a_addon_function[1];
var dest_path = ( options.env === "tests" || ( options.env === "dist" && options.type === "premium" ) ) ? build_path + addon_dirname + "/" + addon_dirname : build_path + addon_dirname;
return gulp.src( [ "./plugins/addons/" + addon_dirname + "/**/*", "./plugins/_common/**/*", "./plugins/addons/_common/**/*" ] )
.pipe( gulp.dest( dest_path )
);
});The file.htaccessis never copied. Why ? How to resolve this ? | Copy .htaccess (a dotfile) with gulp failed |
I try this with Apache2 2.4.27 in win:First enable vhost in httpd.conf file.vhost:<VirtualHost *:80>
ServerName site.ws
DocumentRoot /home/me/Projects/website/build
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/me/Projects/website/build>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>.htaccess:###START MOD_REWRITE
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#REMOVE .html EXTENSION
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
###END MOD_REWRITE | I created a virtual host with this code :<VirtualHost *:80>
ServerAdmin[email protected]ServerName site.ws
ServerAlias www.site.ws
DocumentRoot /home/me/Projects/website/build
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/me/Projects/website/build>
Allow from all
Satisfy any
</Directory>
</VirtualHost>and I created a .htaccess file in my /build directory with this code :RewriteEngine On
RewriteRule ^(.*)$ $1.html [R,NC]Consider my mod_rewrite is active in apache2, but I can't open pages with /filenamee.g site.ws/aboutIt shows error :
The requested URL /about was not found on this server. | How can i set htaccess file for virtual host? |
Since WordPress seems to be located in /wordpress/, changeRewriteRule . /index.php [L]toRewriteRule . /wordpress/index.php [L]? | My system is MAC and I am running Xampp for mac.I search for many solutions and I thought it must be because of my .htaccess missing file , that all my rest of the links in wordpress even my posts, pageexcept my homepageredirects to localhost/dashboard which is xampp's dashboard.# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPressThis is my .htaccess file , and I have all set<Directory />
AllowOverride all
Require all denied
</Directory>in apachehttpd.conffileNow what else I can do? I am stuck with this, Even when I click the permalink on my wp-admin page, it shows no object found, 404 error. The page exits, the post exists, everything exists and still I can see only homepage. | Wordpress redirect to xampp's dashboard except homepage |
The first 2 rewrite conditions will ignore existing files and directories, but the root directory (normally) always exists. Try to remove the first block.This will be sufficient:RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]For angular routes to work you need another block like thisRewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.htmlThat way all non SSL traffic will be redirected. The second part will rewrite everything to your angular index file, except existing directories and files | All I want to do is preventing the site for going http rather than https. Here is my .htaccess configuration. Only www.mywebsite.com and mywebsite.com doesn't go https. Angular routes are ok too. If i write mywebsite.com/signup it goes https as well. What should i do to be able to redirect all scenarios to https ?SCENARIOS:www.website.com -> not httpswebsite.com -> not httpswebsite.com/signin -> httpswww.website.com/signin -> httpsRewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^ /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | HTTP redirect to HTTPS while keeping angular routes (.htaccess) |
You can use this rule to strip all query strings except whenparam3=is found in it.RewriteEngine On
RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !(?:^|&)param3= [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE] | I am trying to remove certain url parameters from the urls. Those parameters have no effect on the content being displayed anymore, but google have a bunch of them indexed.I would like to redirect them to the base url.Here are the examples.Fromwww.myexamplesite.com/?start=10To:www.myexamplesite.comFromwww.myexamplesite.com/folder1/?start=10To:www.myexamplesite.com/folder1Fromwww.myexamplesite.com/folder2/?start=10To:www.myexamplesite.com/folder2Actually I don't need to have any urls with parameters, so I am wondering if there can be a way to catch and redirect all other possible parameters from the urls, and only allow some selected ones that I will specify in htaccess.Examples:Fromwww.myexamplesite.com/?param1=10To:www.myexamplesite.comFromwww.myexamplesite.com/?param1=10¶m2=20To:www.myexamplesite.comFromwww.myexamplesite.com/folder1/?param1=10To:www.myexamplesite.com/folder1Fromwww.myexamplesite.com/folder1/?param1=10¶m2=20To:www.myexamplesite.com/folder1But for param3 which should be my selected one:Fromwww.myexamplesite.com/folder1/?param3=10leave untouched:www.myexamplesite.com/folder1/?param3=10UpdateI actually have already implemented a solution, but my main problem is that it always redirect to the home page and not the appropriate REQUEST_URI...Here is what I have:RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !^item=
RewriteCond %{REQUEST_URI} !^/manage
RewriteRule .? http://www.myexamplesite.com%{REQUEST_URI}? [R=301,L] | htaccess remove the parameter from url |
Add the following in the file "/assets/user-images/.htaccess"RewriteCond %{REQUEST_URI} ^/assets/user-images/(.*)\.jpg$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ default.jpgThe first RewriteCond will check whether the incoming request is for a jpg file under /assets/user-images/ or not and the second RewriteCond with -f option will check whether the requested file exists or not. If it does not exists the RewriteRule will serve the default image.
The end user will still see the URL of the original image but the default image will be served.
If the original image file exists this rule will not execute. | In a pure client based web app I need to show a background image that sometimes doesn't exist. Is there a way of 'forcing' Apache to serve an image when a specific URL pattern returns a 404 error?The URL pattern that might return a 404 is:http://host/assets/user-images/xxxxx.jpgWhere I want to serve the image:http://host/assets/user-images/default.jpgNOTE:I already use a .htaccessRewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L] | Apache show a default image when there is a 404 error under a specific URL pattern |
This can be achieved by using rewriteConditions:https://wiki.apache.org/httpd/RewriteCondSomething along the lines of:RewriteCond %{HTTP_HOST} ^site1
RewriteRule ^old-route$ https://www.site1alt.com/new-route [R=301,L] | Is it possible to redirect from one domain to another using htaccess?RewriteRule http://www.google.com/old-route http://www.google.com/new-route [R=301,L]
RewriteRule https://www.google.com/old-route https://www.google.com/new-route [R=301,L]If not, how would you do the redirect for multiple domains on one project? | htaccess redirect with full url |
I also installed opencart 2.2.I tried the extension for https but it crashed everything ;(I found a working solution 3 Steps :•• 1 ••
in .htaccess : Added at the endRewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} store
RewriteRule ^(.*)$ https://www.__your_domain__.com/store/$1 [R,L]•• 2 ••in config.php in root + admin<?php
// HTTP
define('HTTP_SERVER', 'https://www.__your_domain__.com/store/');
// HTTPS
define('HTTPS_SERVER', 'https://www.__your_domain__.com/store/');**** even with https:// in the browser wasn't enough.... in the source every links where http:// ....
**** So i found this last step•• 3 ••
in system/library/url
Modified http to https and voilà :)public function link($route, $args = '', $secure = false) {
if ($this->ssl && $secure) {
$url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
} else {
$url = 'https://' . $_SERVER['HTTP_HOST'] . rtrim(dirname($_SERVER['SCRIPT_NAME']), '/.\\') . '/index.php?route=' . $route;
} | i install opencart lastest version and i wanna enable all ssl for urlIn admin set SSL enablein config.php both admin and category change to httpshtaccessRewriteEngine On
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]but when url is not SEO it work so url with SEO it not work
the url will behttps://www.localhost/index.php?route=desktops/machow to change tohttps://www.localhost/desktops/mac | Opencart 2.2.x ssl for all request |
To block user agents, you can use :SetEnvIfNoCase User-agent (yandex|baidu|foobar) not-allowed=1
Order Allow,Deny
Allow from ALL
Deny from env=not-allowed | I am so tired of Yandex, Baidu, and MJ12bot eating all my bandwidth. None of them even care about the useless robots.txt file.I would also like to block any user-agent with the word "spider" in it.I have been using the following code in my .htaccess file to look at the user-agent string and block them that way but it seems they still get through. Is this code correct? Is there a better way?BrowserMatchNoCase "baidu" bots
BrowserMatchNoCase "yandex" bots
BrowserMatchNoCase "spider" bots
BrowserMatchNoCase "mj12bot" bots
Order Allow,Deny
Allow from ALL
Deny from env=bots | Use .htaccess to Block Yandex, Baidu, and MJ12bot |
Try the following code in htaccess.RewriteEngine on
RewriteCond %{THE_REQUEST} POST /api/mypath/foo [NC]
RewriteRule ^ - [R=200]This will return the 200ok status for /api/mypath/foo if it is accessed using POST method. | I want apache to return a status code of 200 in response to post requests on a specific pathe.g. /api/mypath/fooIs this possible with a RewriteRule? | How do you make apache return a status 200 response code on a post to a url |
Since the question is already answered in the comments, this is just to provide an answer in the way how Stackoverflow designated it.Like in the question it can be solved by usingmod_headersofApache 2. SinceContent-Dispositionis not part of the standard ofHTTP, you may add some other header to achieve your objective.<FilesMatch "\.(wsc)$">
Header set Content-Type application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>Another thing you should consider is that your browser may cache the responce of the server. The browser will still send the request, but the request will contain a node that the browser already have the file from a given date. If the files hasn't changed since the given date, the server will not send the new headers to your browser. This means if you change the.htaccess, you may not see any impact until you disable caching in your browser or you change the timestamps of the file.You can also addHeader set X-Content-Type-Options "nosniff"for better compatiblity (and maybe security). It prevents the browser from doing MIME-type sniffing, which would ignore the declared content-type. Seeherefor more information. | So I am using the following rule in the htaccess:AddType SCHM wsc
<FilesMatch "\.(wsc)$">
ForceType SCHM
Header set Content-Disposition attachment
</FilesMatch>But when I go to thefile's locationit doesn't force the download | Force file to download with .htaccess |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.