Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
You would want to do a 301 in this instance. In general, if you're trying to figure out which method is best practice, it's usually the choice that makes it clear to the client what is going on. Transparently re-writing makes it look like three domains have the same content. A 301 politely informs the client that the content resides somewhere else.
I have multiple domains pointing at the same website. (FFFF.com, FFFF.ca, FFFF.org, etc)What's the best way to achieve a rewrite to FFFF.com all incoming traffic?URL rewrites or 301s? Looking for best practice. These two would be dealt with within htaccess right?Thanks,
Multiple domains to single website
Try using below codeRewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico AddType video/ogg .ogv AddType video/ogg .ogg AddType video/mp4 .mp4 AddType video/webm .webm AddType application/x-shockwave-flash swf
This question already has answers here:mp4 in safari fails with htaccess authentication(6 answers)Closed11 years ago.i m just working on a private page with some videos, which should only be accessible through htaccess. all videos are html5 encoded, and the site works fine for every browser without the htaccess file.after putting the htaccess file to my server, safari fails to load the mp4-videos. in charles i get an "401 Authorization Required".i checked several posts here to the same topic, but didn't found a solution yet. if someone can push m in the right direction, go ahead!some people solved this issue, while adding the mime types to the htaccess-file (see below). didn t work for me...anyone any ideas?htaccess at root folderAuthUserFile /rootpath/.htpasswd AuthGroupFile /dev/null AuthName "Password Protected Area" AuthType Basic AddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/mp4 .mov AddType video/webm .webm <limit GET POST> require valid-user </limit>htacess in video folderAddType video/ogg .ogv AddType video/mp4 .mp4 AddType video/mp4 .mov AddType video/webm .webmeven checked it with some html5-example videos, so couldn t be wrong codec. keep in mind, it works perfect without the htaccess file, so i guess my configuration is still wrong. but i have no idea where the bug is...
Safari html5 video mp4 not playing in htaccess folder, [duplicate]
You talk about /system, while your code uses /subdomain, so I will use the latter.RewriteEngine On # rewrite subdomains to separate folder RewriteRule ^subdomain/ - [L] RewriteCond %{HTTP_HOST} !^www\.domain\.com$ RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ RewriteRule ^(.*)$ subdomain/$1 [L] # or if you want to rewrite sub.domain.com/test to /subdomain/sub/test #RewriteRule ^(.*)$ subdomain/%1/$1 [L] # force www RewriteCond %{HTTP_HOST} ^domain\.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [R] # BEGIN WordPress RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ./index.php [L] # END WordPress
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed12 years ago.Improve this questionI currently have Wordpress installed in the base path of my server. Wordpress uses htaccess for user-friendly URL's. In addition I have the need of wildcarded subdomains, as I have users wanting to access a specific system.When the user visits www.domain.com, or just domain.com, they should be served Wordpress. If they are requesting giraffesinafrica.domain.com, the dir should be set to /system/ (a folder in base path)In the folder /system/ i have another .htaccess controlling the URLS redirected into that..I hope someone can lead me on the way :)Thanks in advance!RewriteEngine On # 3. internal redirect to the shop RewriteCond %{REQUEST_URI} !-f RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ RewriteRule ^(.*)$ subdomain/ [L,NC,QSA] # BEGIN WordPress RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ./index.php [L] # END WordPress
Wordpress and subdomains htaccess [closed]
Try adding a .htaccess file into your test folder instead.I use this .htaccess content:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?/$1 [L]In the foldertestI would place another .htaccess, with almost the same content:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /test/index.php?/$1 [L]
I want a second website in my domain inside the folder testwww.mydomian.com/testApache server running on linux.But when I load it in my navigator styles, images, helpers can't be found.My htaccess is like this:RewriteEngine OnRewriteBase /testRewriteCond %{REQUEST_URI} ^system.* RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /test/index.php?/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L]Thank you in advanceI have tried what you said, placing the htaccess file you gave me in the test folder and the other one in the root directory, it didn't work.Other options?
CodeIgniter htaccess subfolder problem
You need to usemod_rewriteand here is thefirstandsecondguide.In your case just create.htaccessfile in root folder and write following codeRewriteEngine On RewriteRule ^([^/]*)\$ /index.php?page=$1 [L]
in my website I have links like this -http://example.com/index.php?page=aboutand I want to make them look like this -http://example.com/aboutIs it possible and if it is what should I do to get this result?
Rewriting URL address on a site
Copy this code to your .htaccessRewriteEngine On RewriteBase / RewriteRule ^theme/([a-z]+)/([a-z\-_\.]+)$ /$1/$2 [QSA,L](Make sure mod_rewrite is enable)All the<img src="/images/image1.jpg">will redirect to<img src="/theme/images/image1.jpg">as well all the CSS files.
I wonder if anyone can help with the below and if it is even possible.I have a server running apache and know a little about url re-writing and wondered if it is possible to use url rewriting for paths for images and css.so my current file structure is this:/index.php /theme/css/default.css /theme/images/image1.jpgin index.php i have the css linked to/theme/css/default.cssbut what i would actually like to display is/css/default.cssalso images are the same where i include an image it is<img src=/theme/imaages/image1.jpg>is it possible through rewriting to have<img src=/imaages/image1.jpg>Thanks.
URL Rewriting for images and css
Use theNEflagto keep characters like?in their raw form instead of turning them into %-escapes, losing their special meaning.Howevermod_rewriteis a clumsy way of doing a simple redirect. If you can get access to the main/virtual host config you are better off usingRedirect, the tool that was designed for this job:<VirtualHost *:*> ServerName host.domain.com ... real host settings... </VirtualHost> <VirtualHost *:*> ServerName host Redirect permanent / http://host.domain.com/ </VirtualHost>
I have a machine that is local and if you type inhttp://hostit goes to the website on it. I want to use an htaccess to redirect tohttp://host.domain.com. In the end it is the same I just want to use the proper url for documentation purposes. I tried this but didn't workOptions +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^host [nc] rewriterule ^(.*)$ http://host.domain.com/$1 [r=301,nc]`
htaccess redirect hostname to FQDN
From themanual:URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), or be a full URL which the client can resolve. Alternatively, a message can be provided to be displayed by the browser.This threadmay help you fix it though.
I am very new to Apache and .htaccess, and I had a simple question regarding how to handle 403 and 404 errors with Apache's ErrorDocument command.Let's look at this code from an early CMS I wrote:ErrorDocument 404 /admin/includes/access_deny.php?error=404This will silently redirect the user tohttp://www.mysite.com/admin/includes/access_deny.php?error=404when they get a 404 error.Here is my problem, this error document will always be in the same place, with regards to the .htaccess file. However, if I need to move my installation, say to the directorysubfolder, I will need to open the .htaccess file an update the to following, for it to work correctly:ErrorDocument 404 /subfolder/admin/includes/access_deny.php?error=404Is there a way I can have .htaccess redirect to this pageadmin/includes/access_deny.php?error=404in regards to the file itself, not an absolute URL? Also, no matter where I would move the installation in the future, Apache will catch all 404 errors that are on the same level or sub-directories to this file.Please let me know if that is not clear.Thank you for your time.
.htaccess ErrorDocument Redirect
You can try something along these lines:RewriteCond %{HTTP_HOST} !^(www\.)?main-domain\.com$ [NC] RewriteRule ^(.*) http://www.main-domain.com/$1?domain=%{HTTP_HOST} [R=301,L]With this any requestNOTfor domainwww.main-domain.comwill be redirected towww.main-domain.comwith the domain name in query stringdomain.
I have a client that has a good amount of domain alias' and wants them all redirected to the one main domain on the site. They also want to know which of the domain alias' is doing the redirecting. I have that part down but I want to optimize the code to the best most proper way it should be and to eliminate the amount of code I have to write. I am wanting to know if there is a way to pass to the RewriteRule url the domain alias that was used.This is what I have now. I am looking for the domain alias that is being hit and then passing that alias to the url. Then in google analytics I can see how many times that url was used to hit the page.RewriteCond %{HTTP_HOST} ^(www\.)?domain-alias1\.com [NC] RewriteRule ^(.*) http://www.main-domain.com/?domain-alias1\.com$1 [R=301,L}But my goal is to not have to write both the condition and rule for every single domain alias.Is there a way to see which alias was hit and then have the rewrite rule automatically add that to the position I have specified?I had originally tried something like this just to see if it would work(although I have tried many different ways):RewriteCond %{HTTP_HOST} ^(www\.)?([a-z]+)\.com [NC] RewriteRule ^(.*) http://www.main-domain.com/?$1\.com$2 [R=301,L]
.htaccess redirecting domain alias'
This's what I needed for the rules to work:RewriteEngine on Options +FollowSymlinks RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)/$ $1.php [L]
About an hour ago, I AddedOptions +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_URI} ^(.*[^/])/?$ RewriteCond %{DOCUMENT_ROOT}%1.php -f RewriteRule .+ %1.php [QSA,L]to my.htaccessfile. but It doesnt work. when I go to mywebsite.com/info or mywebsite.com/info/ it doesnt work (the page is info.php). the mod_rewrite is enabled - tested it by RewriteRule that redirected me to google from any page in my site.I have no idea what's the problem.. maybe the code is wrong?Thanks.
mod_rewrite enabled but does not work properly
I’m surprised that this does work at all in a per-directory context as you would have to strip the per-directory path prefix from the pattern:When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automaticallyremovedfor theRewriteRulepattern matching and automaticallyaddedafter any relative (not starting with a slash or protocol name) substitution encounters the end of a rule set.In case of the document root directory that would be the leading/and the rule would look like this:RewriteRule ^directory/(.*)\??(.*)$ /directory/?page=$1&$2But besides that,RewriteRulecan only check the URI path and not the query; you needRewriteCondto do that. So try this:RewriteRule ^directory/(.+)$ /directory/?page=$1 [QSA]Here the.+instead of.*should avoid an infinite recursion as.*matches everything, even an empty string (that would be the case for the empty path segment after/directory/). And theQSAflagis to automatically append the requested URI query to the new one.
I have some specific needs for a certain directory of my website. I need to change/thisDirectory/subDirectoryto come through as/thisDirectory?param=subDirectoryI'm having issues successfully creating an htaccess file that will do that. I've tried SEVERAL different things, but I think this is the closest:RewriteEngine On RewriteRule ^/directory/(.*)\??(.*)$ /directory/?page=$1&$2I've been facing all kinds of 500 Server Errors, infinite redirect loops, etc etc. Any help would be much appreciated, thanks!
htaccess rewrite subdirectory name to querystring param
I posted this question onto serverfault.com and icyrock solved it. Incase anyone else is wondering the answer given is here:https://serverfault.com/questions/203780/troubleshooting-a-htaccess-wildcard-subdomain-rewrite/203804#203804Tim
I know there is a lot of questions on here about this... but right now I feel like a deer stunned by oncoming headlights... I just don't know where to start and which option to choose.My requirements are simple.User goes tohttp://application.domain.comorhttp://www.application.domain.comand the real location of these files ishttp://www.domain.com/applicationObviously this needs to be done using wildcards so that any domain (even if it doesn't exist) triggers the rewrite.I hope this makes sense to someoneEDIT: I should also mention I have added the wildcard A record to my DNS entries in Cpanel *.domain.comThanksTim
Simple .htaccess subdomain rewrite
Determining Referer in PHPCheck if$_SERVER['HTTP_REFERER']is in your domain (or a list of acceptable domains)Then redirect if not.if (!empty($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], 'yourdomain.com') !== false) { echo 'probably from your own site'; }
I don't want to allow people to go directly to the pages in the AJAX directory but they still need to be served from their parent page. I have tried numerous .htaccess lines but they all block it from the main page as well. to sum up, I dont want people to be able to type inhttp://www.mysite.com/AJAX/page1.htmland view it but page1.html needs to be brought into its parent page via AJAX.<LIMIT GET POST> Order deny, allow deny from all </LIMIT>blocks all accessCan you define a flag in the parent filedefine('IS_IN_SCRIPT',1);and check for it in the AJAX pages? will that work with AJAX pages or only PHP includes?
restrict direct linking to AJAX pages in a certain directory
What about this one?RewriteEngine On RewriteRule ^FOO/(.+)/BAZ$ FOO/NEW/BAZ [L,R=301]EDIT:Not sure, but you may need to pass the whole address, here's another sample of code:RewriteEngine On RewriteRule ^FOO/(.+)/BAZ$ http://site.com/FOO/NEW/BAZ [L,R=301]2nd edit:Here's the final solution. I've tried it today on a shared hosting and it worked well.RewriteEngine On RewriteRule ^FOO/(.+)/BAZ$ http://site.com/FOO/NEW/BAZ/ [L,R=301]The only difference is that the last example contains a slash (/) at the end of the new path.
I'd like to redirect:http://site.com/FOO/BAR/BAZtohttp://site.com/FOO/NEW/BAZso, subsitute the second segment in my URL with a new one.ideally I'd like to use HTACCESS and a 301 as these pages have permanently moved.The URL structure will not change. Ideally there won't be a query string, but doesn't matter too much is there is.thanks8EDIT* - I should clarify and say that "BAR" is not a wildcard - it is one word. the real life example is:old Links:site.com/events/details/XXXnew links:site.com/events/VIEW/xxxI don't want:site.com/events/add-newto redirect. JUST if the second segment equals "details" in my case.further clarificationsorry haven't been exactly clear.Existing URL:site.com/events/details/%wildcard%should redirect tosite.com/foo/view/%wildcard%but nothing else.
htaccess 301 redirect certain URL pattern
If you just want it to pick up the php file without informing the browser:RewriteEngine On RewriteRule ^/\?ACT=jquery$ index.php/?ACT=jquery [PT,L]If you want the browser to change bookmarks etc. to create a cononical URL:RewriteEngine On RewriteRule ^/\?ACT=jquery$ index.php/?ACT=jquery [R=301,L]Assuming arbitrary arguments:RewriteEngine On RewriteRule ^/\?(.*)$ index.php/?$1 [PT,L]Or you might prefer a script alias:ScriptAliasMatch ^(.*)\?(.*)$ index.php
I'm trying to do a very simple rewrite of a query string and I'm having no luck at all. I need to go fromhttp:// example dot com/?ACT=jquerytohttp:// example dot com/index.php?ACT=jqueryThis is the code that I've written in my .htaccess file and it throws me an internal server error. I'm really new at this whole mod rewrite business so any help would be greatly appreciated.RewriteEngine OnRewriteCond %{query_string} ^(ACT=jquery)$RewriteRule ^(.*)$ index.php/?ACT=jquery
Rewrite query string in .htaccess
I've actually realized the problem is that public/ is not in the root directory. It is in the same directory that .htaccess is in. Is there a way to get the directory that .htaccess is in, so this can work in different locations without requiring manual modification of the .htaccess for each?You can do it a subrequest. The-Fflag will treat relative paths as relative to the directory the .htaccess is in. So:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond public/$0 !-F RewriteRule ^(.*)$ index.php?$1 [L,B]Note that the-Fimplies a bigger performance penalty than-f, since instead of just a stat, a subrequest is generated. You should also add theBflag to escape your back reference.
I want to use mod-rewrite to check for a file in two separate locations: at the requested URL, and at the requested URL within the "public" directory.Here's what I have so far:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/public/$0 !-f #this line isn't working RewriteRule ^(.*)$ index.php?$1 [L]It can correctly determine if the file is there, but it's not correctly determining if the file is at /public/supplied/file/path/file.extension. How do I test for that?
Using altered RewriteCond to check if file exists in multiple locations
The problem is that you need to provide the absolute file system path to get-fand-dworking. If you’re in the document root, you can use this rule:RewriteCond $1 !^subs/ RewriteCond %{DOCUMENT_ROOT}/subs/default/$1 -f [OR] RewriteCond %{DOCUMENT_ROOT}/subs/default/$1 -d RewriteRule ^(.*)$ subs/default/$1 [L]But if you’re somewhere else, it’s going to be hard to get the right path prefix.
I already have two rewrite rules that work correctly for now but some more code has to be added to work perfectly.I have a website hosted at mydomain.com and all subdom.mydomain.com are rewrited to mydomain.com/subs/subdom . My CMS has to handle the request if the file being reached does not exist, the rewrite is done like so:RewriteCond $1 !^subs/ RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ subs/%1/index.php?page=$1 [L]My CMS handles the next part of the parsing as usual. The problem is if a file really exists, I need to link to it without passing through my CMS, I managed to do it like this:RewriteCond $1 !^subs/ RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ subs/%1/$1 [L]So far it seems to work like a charm. Now I am being picky and I need to have default files that are stored in subs/default/. If the file exists in the subdomain folder, we should grab this one but if not, we need to get the file from the default subdomain. And if the file does not exist anywhere, we should be using the 404 page from the current subdomain unless there is none.I hope it describes well enough. Thank you for your time!
mod_rewrite if file exists
TryRewriteCond %{HTTP_HOST} ^xxx\.yyy\.com RewriteRule (.*) http://zzz.com/$1 [R=permanent,QSA,L]
Say I have a subdomainxxx.yyy.comrunning Apache. The files are stored in/home/someone/public_html/xxx.What I want to do is redirect all requests to a domain namezzz.comwhich is using the same location for its files. (In other words,xxx.yyy.comandzzz.comare aliases for each other)I just want people accessingzzz.com, so if someone goes toxxx.yyy.comthey should be redirected tozzz.com.Can this easily be done with a rewrite rule in an .htaccess file?
How can I redirect all traffic from one domain to another with an .htaccess file?
Options +FollowSymlinks RewriteEngine on RewriteCond %{REQUEST_URI} !/holding_page.php$ RewriteRule $ /holding_page.php$l [R=307,L]Use 307 (thanksPiskvor!) rather than 302 -307 means:The requested resource resides temporarily under a different URI. Since the redirection MAY be altered on occasion, the client SHOULD continue to use the Request-URI for future requests.
I have to put a site down for about half an hour while we put a second server in place. Using .htaccess, how can I redirect ANY request todomain.comtodomain.com/holding_page.php?
htaccess: how to redirect all pages to a holding page
What you are asking will make the client loop forever.neemoil.com.au/shop #would be redirected to neemoil.com.au/ #which in turn would be redirected to neemoil.com.au/shop #and it would keep on looping... neemoil.com.au/ neemoil.com.au/shopYou can use htaccess redirects like this:If it is not a filename, nor a directory and the request URI is shop OR pay OR etc... redirect it to your address...RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (shop|pay|secure|etc) RewriteRule ^(.*)$ www.neemoil.com.au [R=301,L]
I'm having trouble with setting up an htaccess redirect.I need to redirect the following URL:neemoil.com.au [OR] www.neemoil.com.autoneemoil.com.au/shopI also want it to redirect:neemoil.com.au/shop/*toneemoil.com.au/*Can anyone help?
Htaccess redirect
Drop this into the.htaccessfile of the old site (adjusting the domain to your actual one):RewriteEngine On RewriteRule ^(.*)$ http://example.com/blogs/string/$1 [R=301]This will grab this part of the URL at the old site:year/month/dd/string-pulled-from-titleand redirect it to the new site under the new location:blogs/string/year/month/dd/string-pulled-from-titleAlternatively, if you want something a little more variable like, without having to custom fix each.htaccess, drop this in the file for each subdomain instead:RewriteEngine On RewriteCond %{HTTP_HOST} ^(.*).example.com RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]If you're redirecting to the same domain, and it includes thewww, adjust the rewrite rules to the following:RewriteEngine On RewriteCond %{HTTP_HOST} ^(.*).example.com RewriteCond %{HTTP_HOST} !^www.example.com [NC] RewriteRule ^(.*)$ http://example.com/blogs/%1/$1 [R=301,L]Note the secondRewriteCondwhich checks to make sure that the URL requesteddoes notinclude the leadingwww, which may lead to an endless redirect if the destination URL itself includeswwwand would try and redirect that subdomain as well.%1grabs the first capture group from the line above.$1references the first capture group on the same line.
I'm restructuring a web site with a great deal of content currently parked at URLs that look like this.http://string.domain.com/year/month/dd/string-pulled-from-titleFor various reasons, I'd like to park all new content at URLs that looks like thishttp://www.domain.com/blogs/string/year/month/dd/string-pulled-from-titleI'd like to make the change for future content, but don't want all the old stuff to go 404.I believe a 301 redirect rule in my htaccess will do the trick, sending all referred traffic coming in through old links to the new formats.But what should this rule look like? I've read a few tutorials but haven't found this exact case in any examples.Note, I don't want to do this for all subdomains, only for about 10 specific ones. So if someone could help me figure out one of these, then I can copy paste it 10 times in my htaccess for each subdomain and be set.
htaccess redirect for subdomains -> similarly-named subdirectories?
You have to specify the query in the replacement to override the original:RewriteCond %{HTTP_HOST} !^blog\.example\.org$ [NC] RewriteRule ^ http://blog.example.org/index.php? [R=301,L]
I have a site that has been up for some time. I had a blog on a subdomain for some time. I have decided to do away with the main site and just support the blog subdomain.I have a redirect setup for this, but it carries all the extra parameters through to the blog which results in a file not found page appearing. I just want the redirect to go to the index page without parameters.What I currently have in my .htaccess file is thisRewriteCond %{HTTP_HOST} ^.*$ RewriteRule ^/?(.*)$ "http\:\/\/blog\.foo\.org\/index\.php" [R=301,L]When I get a request tohttp://www.foo.org/foo/foo/?module=fooit redirects tohttp://blog.foo.org/foo/foo/index.php?module=fooI want it to redirect tohttp://blog.foo.org/index.php
Use htaccess to redirect all traffic from root to specific subdomain page
You can not do this with JavaScript.But you can use PHP as follows<?php header("Location: https://example.com", TRUE, 301); exit; ?>Syntax headerheader(header, replace, http_response_code)
I am a web developer who also works in SEO. I want to 301 redirect one page to another page. Is this 301 redirect for Google beyond what I write below for you?InJavaScript:<script> window.location.replace("https://example.com"); </script>InPHP:<?php header("Location: https://example.com"); ?>Are these two 301 redirects, or do we have to write.htaccessin the cat file, for example?
Is a 301 redirect the same as changing window.location?
+25I suspect your question is missing some details, or there are mistakes, because it isn't fully explained how you want to redirect all variations of the URL.If you want to redirect the "main domain" as you say, totheme01every time as a default, you will need a separate rule to match only that case when there is no "subdomain" in the URL:RewriteRule ^/?ws/([\w\.-]+)$ /wp-content/themes/theme01/core/$1 [L]This redirectshttp://domain.ltd/ws/web.phpto/wp-content/themes/theme01/core/web.phpand you are effectively treatingtheme01as the default theme.You then need a second rule to redirect all variants containing a "subdomain" and use that as the theme name (which is what it seems like you want to do):RewriteRule ^/?([\w-]+)/ws/([\w\.-]+)$ /wp-content/themes/$1/core/$2 [L]This redirectshttp://domain.ltd/subdomain2/ws/web.phpto/wp-content/themes/subdomain2/core/web.php.
I want to be able to rewrite the following website structure so it applies to both the main domain, and then all subdirectories.domain.ltd | | wp-content | | themes | | theme01 | | core | | web.php # http://domain.ltd/wp-content/themes/theme01/core/web.php | |- subsite1 | | wp-content/themes/theme02/core | | web.php # http://domain.ltd/subsite1/wp-content/themes/theme02/core/web.php | |- subsite2 | | wp-content/themes/theme03/core | | web.php # http://domain.ltd/subsite2/wp-content/themes/theme03/core/web.phpI have the following.htaccessrules:RewriteRule ^([_0-9a-zA-Z-])/ws/(.*) /wp-content/themes/$1/core/$2But I cant figure out why it wont match. I have tried using thehttps://htaccess.madewithlove.betester but couldn't find the correct pattern.Essentially I would want the URLs to be:http://domain.ltd/ws/web.php http://domain.ltd/subsite1/ws/web.php http://domain.ltd/subsite2/ws/web.php
Rewriting URL with variable subdirectory not working
There are few things you need to make sure working :Is your route working in standard HTTP mode withoutindex.phpin url. Like sometimes laravel.com/aboutus does no work but laravel.com/index.php/aboutus works. If its the case, you need to enablemod_rewritesin php and then addAllowOverride Allin your virtualhost configurations and restart apache.Coming to HTTPS, what you have setup in laravel will make laravel request forwarded to a secure HTTPS url. However, your server must be able listen, handle and respond to HTTPS request.You need to enable yoru virtualhost to listen to port443which is the SSL port. Also, if you have SSL certificates, those need to be configured as well.Before knowing if laravel works on HTTPS, make a simple php file and try to access it using HTTPS of the server url. If that works then you can check whats wrong in laravel. If that does not, then SSL is no configured correctly on your server.Lastly, check.htaccessrewrite conditions.php artisan config:clearandphp artisan route:cacheHope this helps to debug this
I have project and I installed SSL certificate on ubuntu server. I have done every solution I found but still getting this message every time I open a page.The requested URL /about was not found on this server.Here is what I have changed to force Laravel to use https:1- I have changed .htaccess in my public folder and added these lines# Added to Force HTTPS RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]2- In app->Providers->AppServiceProvider I have add this to boot() functionif (App::environment() === 'production' || App::environment() === 'dev') { URL::forceScheme('https'); }3- I have created php artisan make:middleware ForceSSL and added the below code to the handle functionif (!$request->secure() && in_array(env('APP_ENV'), ['stage', 'production'])) { return redirect()->secure($request->getRequestUri()); } return $next($request);and in Kernal.php\MyApp\Http\Middleware\ForceSSL::classIn .env file I have changed the APP_URL to https:// and I have also changes APP_URL in app.php inside config folder.What I have missing here? Since two days I couldn't figure out why :(
Laravel Use HTTPS
+50use nginx on the server that serves the main application. by this way you will not have cors problem neither the user will feel that he's being served on different domain.you can start with this nginx config:location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://YOURTOMCATSERVER:{PORT}; } location /blog { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://YOURBLOGSERVER:{PORT}; }
I have a static javascript app built in React that I've deployed to firebase, and lives atexample.firebaseapp.com.I also have a Node app that serves my main application atwww.example.comand is hosted on Heroku.What I'm trying to figure out is, how do I have the user visit to my static javascript application when visiting a given subfolder, e.g.www.example.com/app?Also, is there a way to do this where I'm not having to deal with CORS issues since they will essentially live on the same domain?
How can I redirect to static javascript app from subfolder in a Node.js app on Heroku?
You need an additional RewriteCond to exclude sitemap.php, otherwise when sitemap.php is requested it will fulfill the two conditions!-dand-fand will again be rewritten to index.phpRewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\ [NC] RewriteRule ^ %1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} !/(sitemap.php)/ RewriteRule ^/?(.*)\.php$ index.php [L,QSA] RewriteRule sitemap.xml sitemap/sitemap.php [L]
I am trying to redirect every php file to index.php except sitemap.xml. The problem is that sitemap.xml is redirected also to index.php. How to redirect all php files to index.php and sitemap.xml to sitemap.php ?RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\ [NC] RewriteRule ^ %1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} -f RewriteRule ^/?(.*)\.php$ index.php [L,QSA] RewriteRule sitemap.xml sitemap/sitemap.php [L]
htaccess - Rewrite all files to index.php except sitemap.xml
+50From your question,You want to redirecthttp://example.com/static/js/min/common.min.1234567890.jstohttp://example.com/static/js/min/common.min.jsSo, How to do thatthe .htaccessFirst addRewriteEngine OnTo turn on the rewrite engineThen the next important line comesRewriteRule ^static/js/min/([^\d]*)(\d{10}).js$ static/js/min/$1js [L]ExplanationSet the path asstatic/js/min/Then we use RegEx to take the string until a non digit.([^\d]*).That iscommon.min.is captured.Now$1iscommon.min.Then to match the url, we use(\d{10})to capture the digits.That is1234567890is captured.Now$2is1234567890which we don't want anymoreThen redirect tostatic/js/min/$1jsNot that here we didn't added the.after the$1because$1ending with a.(common.min.)So, the code will beRewriteEngine On RewriteRule ^static/js/min/([^\d]*)(\d{10}).js$ static/js/min/$1js [L]Working ScreenshotMy File StructureThe Address in Browser
I have this file in my webserver:http://example.com/static/js/min/common.min.jsSince all files inside/static/are cached with CloudFlare's Edge Cache, I need a way to change the url with something like this, so if the file is modified, the new version will be automatically fresh served:http://example.com/static/js/min/common.min.1234567890.jsWhere 1234567890 is the timestamp of the file's date modification. I already generate the filename according to the modification date, the issue I'm having is in the .htaccess file.This works fine:RewriteRule ^(.*)\.[\d]{10}\.(js)$ $1.$2 [L]That means that:http://example.com/static/js/min/common.min.1234567890.jsIs redirected to:http://example.com/static/js/min/common.min.jsBut, that will catch all .js requests from the domain, I just want to catch .js requests from within /static/js/min/*.js -- but this is failing:RewriteRule ^static/js/min/(.*)\.[\d]{10}\.(js)$ $1.$2 [L]What should the rule be like?
Rewrite rule for name.123456.js in htaccess
You can useredirect_canonicalto tell the function to not use this url when try to find the page. Here is the code:add_filter( 'redirect_canonical', 'custom_redirect_canonical', 10, 2 ); function custom_redirect_canonical( $redirect_url, $requested_url ) { if( $requested_url == 'http://example.com/en' ) { return $requested_url; } return $redirect_url; }Please note the following:I do not recommend to use such function. It will be better if you change your folder name to something thatredirect_canonicalwill skip.The above code use hardcoded url which is also not a best practice.
I have a WordPress site and I made a folder inside the WordPress installation folder calleden. So suppose if my site URL isexample.comwhich loads my WordPress site, the visitor should can access the contents ofenfolder by visitingexample.com/en/URL.But unfortunately the WordPress redirects the visitor to a page with URL likeexample.com/environmental-advertising/, which is a blog post.As I understood, WordPress'sredirect_canonicalcausing this redirect.So how can I prevent this type of redirects for a certain URLs likeexample.com/en/?*UPD #1:Theenfolder isanother WordPress installation.
How to bypass WordPress redirect_canonical for a certain URL
try thisRewriteEngine on RewriteCond $1 !^(index\.php|public|\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?$1
My codeigniter is installed in admin_new folder on hostinger and path of installed codeigniter ispublic_html/vishwa/admin_new/and i am trying to remove index.php from url.I have changed my .htaccess file as below.RewriteEngine on RewriteBase /vishwa/admin_new/ RewriteRule ^(application|system|\.svn) index.php/$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [QSA,L]I have checked forums and it says mode_rewrite is enabled as default on hostinger. but it is showing error likeNo input file specified.I have also changed config settings in config.php as below:$config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI';but still it is showing same error. Why this type of error has been shown and how can i solve it.
Remove index.php from codeigniter in subfolder
I cannot answer this in comments so posting this as an answer:RewriteEngine On # remove PHP from root level requests RewriteCond %{THE_REQUEST} \.php[\s?] [NC] RewriteRule ^([^/]+)\.php$ /$1 [R=302,NE,L,NC] # To internally redirect /foo to /foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^([^/]+)/?$ $1.php [L]
This is what my.htaccessfile looks like:RewriteCond %{ENV:REDIRECT_STATUS} 200 RewriteRule .* - [L] #removes trailing slash if not a directory RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ /$1 [R=301,L] #adds ".php" to a URL that isn't a directory or a file RewriteCond %{REQUEST_URI} !(\.[^./]+)$ RewriteCond %{REQUEST_fileNAME} !-d RewriteCond %{REQUEST_fileNAME} !-f RewriteRule (.*) $1.php [L]Although it lets me access the url without the .php in the end for e.g.example.com/sign-upIt does not redirect me fromexample.com/sign-up.phptoexample.com/sign-upIs there any code which I can add to this file to make that happen?Any insight would be very helpful
.htaccess redirection to tidy URL
Linux is case sensitive. Keep in mind in which case you wrote the directory and file name. You should write file or directory name in any file exactly same what file or directory belongs.Please check the file/directory ofuser_authentification. Moreover, the first letter of controller/model should be caps (codeigniter requirements). Please check did you writecontroller/modelname correctly.UpdatePut the following snippets on.htaccessfile:<IfModule mod_rewrite.c> RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA] </IfModule>
Error 404 on linux but work fine on windows. What is causing this?I use this tutorial:http://www.tutora.fr/apprendre-codeigniter/les-controleursapplication/config/routes.php :$route['default_controller'] = 'welcome'; $route['translate_uri_dashes'] = FALSE; $route['login'] = 'user_authentification/user_authentification';application/config/config.php:$config['base_url'] = ''; $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI'; $config['subclass_prefix'] = 'CORE_';Local hosting on Windows (XAMPP) works fine at url mysite.dev/login.Live hosting on Linux produces 404 error at url mysite.pro/login.If I addindex.php(mysite.pro/index.php/login), it work fine but I would remove it.
remove index.php : error 404 on linux but work fine on windows
Here are answers:Q1. did I get lines 1 to 5 right?A1. yes you didQ2. what exactly does line 6 do?A2. It says for any request that is not empty (single DOT will match anything except the landing page) forward to/blog/index.phpQ3. is line 8 explanation correct?A3. Yes it is correct. There is nothing strange. You want to remove/subfolder/in your URLs for your clients but want to addsubfolder/internally/silentlywhen your web server receives a request withoutsubfolder/so that you can load the page correctly.
Using Wordpress as a CMS, the .htaccess file looks like this:RewriteEngine On # 1. ok - enables engine RewriteBase /blog/ # 2. ?? - sets blog directory as base for the rules RewriteRule ^index\.php$ - [L] # 3. ?? - replaces index.php by nothing in the URL RewriteCond %{REQUEST_FILENAME} !-f # 4. ?? - checks if request contains a file name RewriteCond %{REQUEST_FILENAME} !-d # 5. ?? - checks if request contains a directory name RewriteRule . /blog/index.php [L] # 6. ?? --> why this single dot (1 occurrence of a single character)?I read extensive documentation (and still am reading) about mod_rewrite, I know what regex are and how they work, and I got my site working perfectly fine. Yet I'm copying-pasting and not sure to be understanding. Lines with ?? are the ones I am not sure to understand (and I don't get what line 6 does at all).In another file based onhttps://stackoverflow.com/a/20979005(this worked for my site):RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ # 7. ok RewriteRule !^subfolder/ /subfolder%{REQUEST_URI} [L] # 8. ?? - if it does not contain the subfolder, add it (strange as I wanted exactly to remove it from the URL but it works)My questions are:did I get lines 1 to 5 right?what exactly does line 6 do?is line 8 explanation correct?
What does the single dot do in this .htaccess RewriteRule?
You re getting redirect loop due toDirectoryIndexhandler being added in REQUEST_URI.To fix this issue you can use this rule:RewriteCond %{HTTP_HOST} www.localhost$ [NC] RewriteCond %{REQUEST_URI} !^/index\. [NC] RewriteRule ^.+ http://www.localhost [L,R]RewriteCond %{REQUEST_URI} !^/index\. [NC]will stop redirect loop since/index.htmlor/index.phpis usually theDirectoryIndexhandler.
Not sure why this isn't working:RewriteEngine On RewriteCond %{HTTP_HOST} example.com$ [NC] RewriteRule ^.+ http://example.com [L]TheRewriteCondis working as far as I can tell.To me, theRewriteRulereads:^Start the match.+One or more charactersYet,Firefox 44is telling meThe page isn't redirecting properlyFirefox has detected that the server is redirecting the request for this address in a way that will never complete.If theRewriteRulestarted with^.*, I would expect the server to be caught in an endless loop.But^.+ought to work, no?
Simple .htaccess RewriteRule not working
Try this :RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}/$1 [R,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L]
I have found several answers to this question but slightly different, the funny thing is that it didn't work for me.My goal is to rewrite any url to HTTPS and remove the index.phpBasically what I want is to merge the following two htaccess files but I am somewhat new to the htaccess syntax:RewriteEngine On RewriteBase / # If needed add 'www' RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L] RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]andRewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php?/$0 [PT,L]
.htaccess HTTPS and remove index.php
Change the order of your rules and clear your browser cache before you test it:RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] RewriteRule ^ https://www.newdomain.org%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.newdomain.org%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Let's say we have,Old Domain :http://www.olddomain.comNew Domain :https://www.newdomain.orgHere's my .htaccess file data :RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ RewriteRule ^/?$ "https\:\/\/www\.newdomain\.org\/" [R=301,L]Sometimes while redirection, browsers are displaying the Security error such that it is untrusted.Now,How to make this successfull ?How to redirect this from non-www to www ?
Redirect an Old Domain to a New Domain with HTTPS in .htaccess
You can use this rule to get full URL as query parameter:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{HTTPS}s on(s)| RewriteRule ^ index.php?request_uri_path=http%1://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]If you're on Apache 2.4 then you can make use of%{REQUEST_SCHEME}variable:RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php?request_uri_path=%{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI} [L,QSA]
Currently my ApacheRewriteRuleonly passes the path of the original URL as a query parameter to the rewritten URL.How do I send the entire URL (including scheme and authority etc) as a parameter to the rewritten URL?I know%{REQUEST_URI}only passes the path, and I can’t see any Apache environment variables that do pass the entire URL.I’m something of a beginner to Apache configuration so excuse any ignorance on my part,thanks!Here’s my current config:# # Enable Rewrite # RewriteEngine On # # Condition for rewriting the URL. Check the URL's path is a valid REST URI path # RewriteCond %{REQUEST_URI} ^(?:[^?#]*)(?:/v[0-9]+(?:\.[0-9]+)*)(?:/[a-z]+)(?:/[a-z]+)(?:/?[^/?#]*)(?:[^?#]*)$ # # Rewrite the URL, sending the REST path as a parameter to the specified version. # RewriteRule ^(?:[^?#]*)(?:/(v[0-9]+(?:\.[0-9]+)*))((?:/[a-z]+)(?:/[a-z]+)(?:/?[^/?#]*)(?:[^?#]*))$ https://localhost/rest/$1/index.php?request_uri_path=https://localhost/rest/$1/$2 [QSA,NC,L,R=307]Currently I’ve hardcoded the url into the query parameters so the URLhttps://localhost/rest/v1/users/show/12345becomes:https://localhost/rest/v1/index.php?request_uri_path=https://localhost/rest/v1/users/show/12345
Apache RewriteRule pass entire URL as a parameter
I fixed it by doing the following:A. You need a .htaccess on the host where you run the script.<FilesMatch "\.(php)$"> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> </FilesMatch> Header set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Methods "POST, GET, OPTIONS" Header set Access-Control-Max-Age "1000" Header set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"secondly the ERP system also need headers to be set. You can check with curl if headers are correctly set or not.B. Another option: if you do not want to work with headers, or are unable to set some headers then you can use CURL to do the job :when clicking submit on my form, my script will call a .php file in which i have this code:<?php // //code to send json to lotus webservice without cors errors // $jsondata = $_GET['jsondata']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,"102.101.101.11:80/c/orders"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$jsondata); // in real life you should use something like: // curl_setopt($ch, CURLOPT_POSTFIELDS, // http_build_query(array('postvar1' => 'value1'))); // receive server response ... curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = curl_exec ($ch); curl_close ($ch); ?>and it works! no more cors errors! and data send to the server and also received by server :)
I have a javascript file in which i want to send json data to a ERP system:var formData1 = JSON.stringify($('#msform').serializeObject()); $.ajax({ url:'http://102.101.101.11:80/c/orders', type:'POST', data:formData1, crossDomain: true, dataType: 'json', jsonpCallback: 'callback', success: function(data) { //window.location.href = "http://www.petlooza.com"; console.log(data); } });This script works with chrome and IE,but FIREFOX gives me this error:Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at the url. Reason: Cors-request failed.How to fix this?See solution below!
How to fix cross-origin request fail in Firefox
You can use this code in yourDOCUMENT_ROOT/.htaccessfile:RewriteEngine On RewriteBase / # external redirect from actual URL to pretty one RewriteCond %{THE_REQUEST} \s/+directory/(?:index\.php)\?state=([^\s&]+)&city=([^\s&]+)&zip=([^\s&]+)\s [NC] RewriteRule ^ /directory/%2-%1-%3? [R=302,L,NE] # internal forward from pretty URL to actual one RewriteRule ^directory/([^-/]+)-([^-/]+)-([^-/]+)/?$ directory/?state=$2&city=$1&zip=$3 [L,QSA,NC]
For dynamic content on my website, I use urls with query variablese.g. http://www.example.com/directory/?state=NJ&city=Wayne&zip=07474 or http://www.example.com/directory/index.php?state=NJ&city=Wayne&zip=07474I would like to convert them to seo-friendly static urls insteade.g. http://www.example.com/directory/Wayne-NJ-07474/I researched on SO and found it seems like a htaccess rewrite rule is the way to go.I am a noob when it comes to htaccess constructs and what I fail to understand is will I still get the data associated with the individual query parameters i.e. state, city, and zip. Meaning will I still be able to access them via _REQUEST()?I would also appreciate if someone would help me with the rewrite rule for my specific case.
Convert Dynamic URLs with query parameters to static URLs
Your code is looping. This is because you can't match the query string in a rewrite rule, thus a URL like:/buyit.php?qstart=1&gid=73161-645821-36&qid=4&daq=0&preq=14&clk=7actually matches:^buyit\.php$So you need to add a condition to check that there isn't a query string. Change your last rule to this:RewriteCond %{QUERY_STRING} ^$ RewriteRule ^buyit\.php$ /buyit.php?qstart=1&gid=73161-645821-36&qid=4&daq=0&preq=14&clk=7 [L]
I recently tried to hide parameters from my url, using htaccess, ended up with a 500 Server Error.Here is my.htaccesscode:<files .htaccess> order allow,deny deny from all </files> Options -Indexes +FollowSymLinks RewriteEngine on RewriteBase / ErrorDocument 404 /404.php RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s] RewriteRule ^(.+?)/$ /$1 [R=301,L] RewriteBase / RewriteRule ^([^/]+\.php)/.* $1 [R=301,L] RewriteRule ^buyit\.php$ /buyit.php?qstart=1&gid=73161-645821-36&qid=4&daq=0&preq=14&clk=7 [L]All I wanted to do is my page buyit.php?qsta=1&gid=11-64-36&qid=4&kaq=0&req=14&dlk=7 to show always as buyit.php keeping my variables intact and usuable for my php scripts. So I added this last line in htaccess but unfortunately it crashes.Any ideas why, please?
Htaccess new line crashes page
You will need to useFilesMatchwith negative lookahead regex:<FilesMatch "^(?!.*\.(cgi|php|html)$).*$"> SetHandler default-handler </FilesMatch>
I'm trying to set a rule in a directory cgi, this works but I would like to avoid it for .cgi .php and .html filetypes<Files *> SetHandler default-handler </Files>Can I add that exception in a regex way?
htaccess regex for all except some filetypes
Try adding, above your wordpress rules:RewriteCond %{HTTP_HOST} !^([a-z]{2})\.foo\.eu$ [NC] RewriteCond %{THE_REQUEST} \ /+([^\?]*)\?lang=([a-z]{2})&?([^\ ]*) RewriteRule ^ http://%2.foo.eu/%1?%3 [L,R] RewriteCond %{QUERY_STRING} !(^|&)lang= RewriteCond %{HTTP_HOST} ^([a-z]{2})\.foo\.eu$ [NC] RewriteRule ^(.*)$ /$1?lang=%1 [L,QSA]
Hello I have a website that should be available in multiple languages. I made it with wordpress. What I am trying to achieve is that every language get its own (virtual) subdomain. So for example fr.foo.eu and nl.foo.eu.At the moment i have the urls in the following format: foo.eu/?lang=nl foo.eu/?lang=frIt is possible that there is more content in the url for example:http://hypnose.eu/hallo-wereld/?lang=nlAnd i would like to have my urls the following way using htaccess:http://nl.hypnose.eu/hallo-wereld/Could you guys help me with achieving that.Here is what i have so far in my .htaccess:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^([a-z]{2}\.hypnose\.eu$ [NC] RewriteCond %{THE_REQUEST} \ /+([^\?]*)\?lang=([a-z]{2})&?([^\ ]*) RewriteRule ^ http://%2.hypnose.eu/%1?%3 [L,R] RewriteCond %{QUERY_STRING} !(^|&)lang= RewriteCond %{HTTP_HOST} ^([a-z]{2})\.hypnose\.eu$ [NC] RewriteRule ^(.*)$ /$1?lang=%2 [L,QSA] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
htaccess reposition a part of a url
Another option, (as per my comment under question):RewriteCond %{REQUEST_URI} !\.sso/ # exclude Shibboleth extensions RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]...add another condition to the second RewriteRule group, excluding requests that contain a dot-s-s-o-forward slash. :)
I have a wordpress site with Shibboleth plugin installed, Which uses Shibboleth to authenticate users.Site url : www.mytestsite.com/wordpress/blogI wanted to remove the subdirectory from the url so, I followed the below url and accomplished ithttp://codex.wordpress.org/Giving_WordPress_Its_Own_DirectoryNow, I can access the blog without the subdirectorySite url : www.mytestsite.com/blogThe htaccess file looks like this# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPressbut now shibboleth authentication does not work because apache is tring to find shibboleth urls in wordpress and displays page is not found.I'll need to write a RewriteCond which would exclude shibboleth urls.the shibboleth url are:www.mytestsite.com/Shibboleth.sso/Loginwww.mytestsite.com/Shibboleth.sso/Logoutwww.mytestsite.com/Shibboleth.sso/SessionI need help in writing the RewriteCond rule for the above urls, kindly help.
How to write a Mod Rewrite to exclude Shibboleth urls?
You can use:ErrorDocument 404 / RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
I created www domain redirection in htaccess file:RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L] ErrorDocument 404 /All works, but I do not want enter manualy domain name every time. How to change example.com to dynamic domain name? Can somebody help me?
Dynamic domain htaccess redirection
Don't mixRedirectrules withmod_aliasones.Keep redirect rules before internal rewrite ones.You can use this code:Options +FollowSymlinks RewriteEngine on RewriteRule ^testurl/?$ /home/? [L,NC,R=301] RewriteCond $1 !^(index\.php|assets|uploads|tt|application/modules/.*/assets|resources|robots\.txt|favicon\.ico) RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]Better to test in a new browser to avoid old 301 caches.
Options +FollowSymlinks RewriteEngine on RewriteCond $1 !^(index\.php|assets|uploads|tt|application/modules/.*/assets|resources|robots\.txt|favicon\.ico) RewriteRule ^(.*)$ /index.php?/$1 [L] Redirect 301 /testurl /home/This is my.htaccessfile for checking301redirection in my CodeIgniter project.The301redirection works fine but problem is with the URL. When I try...http://parcmobilenew.eworkdemo.com/testurl...it redirects to Home Page as mentioned in.htaccessbut it takes requested URL in query string like this...http://parcmobilenew.eworkdemo.com/home?/testurlHow can I make the.htaccessnot do this when redirecting?
301 redirection in CodeIgniter having ? issue
If you wish to block any IP but only the one in your list and provide a basic login promped for the allowed IPs you can do something like (inside your .htaccess):Require all denied <RequireAll> Require valid-user Require ip 100.04.04.04 AuthBasicProvider file AuthType Basic AuthName "Secure Folder Login" AuthUserFile /htdocs/www/web_projects/.htpasswd </RequireAll>and for multiple IPs something like the following should work:Require all denied <RequireAll> <RequireAny> Require ip 78.53.160.0/19 Require ip 80.171.1.0/24 Require ip 80.171.2.0/23 Require ip 80.171.4.0/22 Require ip 80.171.8.0/21 Require ip 80.171.16.0/20 Require ip 80.171.32.0/19 Require ip 80.171.64.0/18 </RequireAny> <RequireAll> Require valid-user AuthBasicProvider file AuthType Basic AuthName "Secure Folder Login" AuthUserFile /htdocs/www/web_projects/.htpasswd </RequireAll> </RequireAll>
I want to restrict access to a complete website (apache 2.4) to certain IPs. On top of that I want to restrict access to certain subfolders to with user authentication. User auth is not working. Here is what I got:In the vhost config I have<Location /> # Localhost Require ip 127.0.0.1i # some other IP Require ip 1.2.3.4 <Location>Now I want the subfolder /secure/ to require a valid user login<webroot>/secure/.htaccesslooks like<RequireAll> Require all granted Require user user1 user2 user3 AuthBasicProvider file AuthType Basic AuthName "Secure Folder Login" AuthUserFile /securePath/userAuth </RequireAll>I can still access /secure from the IP 1.2.3.4 without user authentication. It feels like apache matches the IP theRequire ip 1.2.3.4directive (inside implicidRequireAny) and doesn't care about possible extra restrictions furhter down the line.
Combine ip and user auth restriction for subfolder in apache 2.4
Alter your env variable to store 0 or 1 and then you can useHeader setlike this:You can use:# set DOCUMENT=widget (remove if you are already setting this) SetEnvIf Host ^ DOCUMENT=widget # set isDoc=1 if DOCUMENT == widget SetEnvIf DOCUMENT widget isDoc # set header only if isDoc == 1 Header set Refresh "3" env=isDoc
How to set a custom header via .htaccess according to an environement variable using If/Else directive?#Refresh-page <If "%{ENV:DOCUMENT} == 'loading'"> Header set Refresh "3" </If>I am trying to use the syntax described in the documentation for Apache 2.4http://httpd.apache.org/docs/2.4/mod/core.html#ifTEST 1According to anubhava's answerRewriteCond %{ENV:DOCUMENT} ^widget$ RewriteRule ^.* - [E=REFRESH:1] #refresh page Header set Refresh "3" env=REFRESH RewriteCond %{ENV:REFRESH} ^1$ RewriteRule ^.* loading.html [L]
.htaccess - How to set a custom header according to an environement variable?
You can replace your current code by this one (your htaccess has to be intestfolder, and it's the same forindex.php)RewriteEngine On RewriteBase /test/ # add trailing slash if no trailing slash and not an existing file/folder RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+[^/])$ $1/ [R=301,L] RewriteRule ^([^/]*)/([^/]*)/$ index.php?page=$1&link=$2 [L] RewriteRule ^([^/]*)/$ index.php?page=$1 [L]You can try these linkshttp://domain.com/test/136/35/internallyrewritestoindex.php?page=136&link=35http://domain.com/test/136/35redirectstohttp://domain.com/test/136/35/http://domain.com/test/136/internallyrewritestoindex.php?page=136http://domain.com/test/136redirectstohttp://domain.com/test/136/
I found this solution online:RewriteEngine On RewriteBase /test/ RewriteRule ^([^-]*)/$ index.php?page=$1 RewriteRule ^([^-]*)/([^-]*)/$ index.php?page=$1&link=$2 [L] #dodaje slash na koncu RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ $1/ [NC,R=301,L]The first one RewriteRule works perfect, it returns me$_GET['page']=130. But when it comes to second one, it returns me$_GET['page']=index.phpinstead of$_GET['page']=130and$_GET['link']=35. That finish with SQL error, because of numeric id of page.Normal link looks like:?page=136?page=136&link=35Rewrited one:/136/- works/136/35/- doesn't work,$_GET['page']=index.php
Mod rewrite htaccess - two variables in rewrite rule
A route rule as below should help:$route['v1/(:any)/(:any)'] = 'api/v1/$1/$2';If v1 is supposed to change like v1, v2 in future, then something similar to below will help:$route['v(:num)/(:any)/(:any)'] = 'api/v$1/$2/$3';
I am writing a REST api in codeigniter usinghttps://github.com/chriskacerguis/codeigniter-restserverREST controller library. I have written my controller insideapplication/controllers/api/v1and override the Router class to allow multiple sub-folders inside controllers.Now I want to access the services ashttp://api.domain.com/v1/user/11instead ofhttp://api.domain.com/api/v1/user/11I have tried following htaccess ruleRewriteCond %{HTTP_HOST} ^api\.domain\.com$ RewriteCond %{REQUEST_URI} !index.php/ RewriteRule ^(.*)/?$ /index.php/api/$1 [QSA,L]But it seems to be not working because REQUEST_URI in the $_SERVER global variable is set tov1/user/11instead ofapi/v1/user/11so codeigniter is unable to find the controller.Is there a way to achieve the requirement except setting the altering REQUEST_URI in index.php?I do NOT want to do permanent redirect.Any help is much appreciated.
Rewrite rule to simplify codeigniter url for REST api
may be you sending some data on post then check in htaccess if url with data then ignore rewrite or use post url in ajax without php extension like url/dataurl: data, //instaed of data.php
I'm trying to modify my htaccess request, it currently loads all the files that are php, but removes the .php extension. However I noticed that this affects my ajax requests, as I cannot get any POST data from them. What do I add to my htaccess to prevent a specific php(data.php) from not being affected by the extension removal of the htaccess?The code of my htaccess:RewriteEngine On # browser requests PHP RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php RewriteRule ^/?(.*)\.php$ /$1 [L,R=301] # check to see if the request is for a PHP file: RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^/?(.*)$ /$1.php [L]
Prevent htaccess from affecting ajax requests
If they strip out the header, you may not even be able to capture it in your htaccess file. But you'd need something that looks like this:RewriteEngine On RewriteCond %{HTTP:X-FORWARDED-FOR} ^(.+)$ RewriteRule ^ - [L,E=X-FORWARDED:%1]And you'd be able to get the environment variable via (using php)$_SERVER['X-FORWARDED']
I'm running my site on a shared server and want to be able to capture the "real" ip address of users who are using the Puffin browser. Puffin renders web site content on its own cloud servers and then passes the result to the user's browser. The downside is that the user's ip address appears as that of the Puffin cloud server and not their own. Puffin does however pass the "real" ip address using the X-FORWARDED-FOR header. Unfortunately my host provider strips this out.I asked them if there was any way round this and they have responded saying (regarding the X-FORWARDED-FOR header):"You may be able to capture this with an environment variable within a .htaccess file."At this point I'm way out of my depth so I was wondering if anyone could explain in simple terms how to go about this?
Capture X-FORWARDED-FOR header via htaccess?
This should work:RewriteEngine on #Create friendly URL RewriteRule ^(data|cache)($|/) - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/?$ /index.php?page=$1 [L,QSA]2nd rule will skip all files and directories from rewrite due to 2RewriteCondstatements.
# php_value session.cookie_domain .rhr.fm # Enable Rewrite Engine RewriteEngine on #Create friendly URL RewriteRule ^(data|cache)($|/) - [L] RewriteRule ^([^/]+) index.php?page=$1 [L]Hello once again Stackoverflow!I would like to redirect URLs for SEO on my website, thatwww.example.com/aboutwww.example.com/?page=aboutandwww.example.com/about/www.example.com?page=aboutBut the dirsdataandcacheget excluded, so thatwww.example.com/data/js/page.jsdoesnotredirect towww.example.com/?page=data/js/page.jsI've tried the code above but that didn't work out -$_GET['page']allways dumpsindex.php.Could you please help me?Thanks in advance!
Htaccess rewrite directories to file
The page that's throwing it is "/". So you want to look at what your index file is in your document root (index.phpfor example). Additionally, make sure that the log is for asitethat you have setup correctly (e.g. not default vhost).If you have multiple vhosts, you may want to create a custom log file for each vhost so you know which one it is that is returning a 500 error. It would be the directives:TransferLogandErrorLog.
I am getting the following 500 in my access logs in rare occasionsIP - - [05/Nov/2013:14:44:52 -0600] "-GET / HTTP/1.1" 500 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)" IP - - [05/Nov/2013:14:44:52 -0600] "GET / HTTP/1.1" 500 - "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"However I cant see what page is throwing it so I was wondering how can I go about troubleshooting and find the page.Thanks
500 error but no info about the link GET / HTTP/1.1" 500 "-"
Look into your error.log as I suspect that either/path/to/defendersquest.com/2/.htpasswddoesn't exist OR doesn't have 644 permissions.Request tohttp://www.defendersquest.com/2/is redirecting tohttp://www.defendersquest.com/1/failed_auth.htmlwhich in turn doesn't exist either and causing it to go tohttp://www.defendersquest.com/1/missing.htmland looping.
I have a website with two subdirectories, /1/ and /2/, appended to the end of the base url. Subsite /1/ already exists, and I'm trying to work on /2/ behind an htaccess password wall.Going to the /1/ site works fine (and the root redirects all work as intended), but going to the /2/ site causes an infinite redirect when my htaccess password challenge is active. What am I doing wrong?Here's the .htaccess file in the root directory:Redirect 301 /theforum http://www.leveluplabs.com/forum RewriteEngine On # stuff to let through (ignore) RewriteCond %{REQUEST_URI} "/theforum/" [OR] RewriteCond %{REQUEST_URI} "/theforum" [OR] RewriteCond %{REQUEST_URI} "/2/" [OR] RewriteCond %{REQUEST_URI} "/update/" [OR] RewriteCond %{REQUEST_URI} "/files/" [OR] RewriteCond %{REQUEST_URI} "/download.php" RewriteRule (.*) $1 [L] # RewriteRule ^(.*)$ http://www.defendersquest.com/1/$1 [R=301,L]Here's the .htaccess in the /2/ directory:### Generated by Dreamhost. DO NOT modify!!! ### AuthType Basic AuthUserFile /path/to/defendersquest.com/2/.htpasswd AuthName "Under construction!" require valid-user ################################################(/path/to/ is not the real path, I redacted the actual server path).Any ideas? The page that generates the error is:http://www.defendersquest.com/2/
htaccess infinite redirect on password-protected subdirectory
You're pretty much out of luck as only the PHP module supports thephp_valueandphp_flagdirectives.What you can do is create aphp.inifile for each website. From memory, you will need this to be a fullphp.inifile as a new file will completely override the system one.One simple way to do this would be copy the system file and then add your custom property, egcp /usr/share/php5/php.ini /path/to/site/php.d/php.ini \ && echo 'include_path = "[INCLUDE PATH]"' >> /path/to/site/php.d/php.iniThen, in the site's.htaccessfile, set thePHPRCenvironment variable. This is to avoid having to add aphp.inifile intoeverydirectory.SetEnv PHPRC /path/to/site/php.dIdeally though, each site should take care of its owninclude_pathin code. This will make your applications much more portable.set_include_path(implode(PATH_SEPARATOR, [ '[INCLUDE_PATH'], get_include_path() ]));
I recently switched to fastcgi and now I have a problem with setting the php include path which had previously been set in .htaccess as:php_value include_path "[INCLUDE PATH]"Since the switch, this gives the error:Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configurationAnd to my understanding 'php_value' cannot be set via htaccess with fastcgi.Are there any ways to get around this or to globally specify the php include path for a whole site with subdirectories, such as through the apache configuration?I know that I can manually set the include path on each script in php or I can specify the include path in a php.ini in the directory, but the websites are already established with many files and directories and it would be cumbersome to go through each file and directory to copy the new include paths or php.ini files.
Using apache configuration to specify PHP include directory for each site
It's hard to understand your setup, you should explain it more. But if I got it right, check /app/Config/core.php:Configure::write('App.fullBaseUrl', 'http://example.com');
I'm trying to setup a CakePHP app in a sub-folder but run it from the root domain, eg, user requestsdomain.co.ukand they get the webroot at{DOCUMENT_ROOT}/version-13/app/webroot.The hosting setup doesn't allow me to change the document root so I have the following .htaccess in the root:<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteRule ^$ version-13/app/webroot/ [L] RewriteRule (.*) version-13/app/webroot/$1 [L] </IfModule>This appears to do the job. However, Cake detects the sub-folder and adds it to all the URLs it creates (eg,$this->Form->create()actions, etc) so I end up with forms posted todomain.co.uk/version-13/signupinstead ofdomain.co.uk/signup.I know this is probably going to be something simple but I'm hitting a brick wall. No matter what I try I can't get it to work!
How do I run a CakePHP app in a sub-folder from the root domain?
Try:RewriteEngine on # first check if request is in /blog/ RewriteCond %{DOCUMENT_ROOT}/blog%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}/blog%{REQUEST_URI} -d RewriteRule ^(.*)$ /blog/$1 [L] # then check if request is in /projects/ RewriteCond %{DOCUMENT_ROOT}/projects%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}/projects%{REQUEST_URI} -d RewriteRule ^(.*)$ /projects/$1 [L] # otherwise, blindly rewrite to blog (or do nothing by removing this rule to allow a 404 not found) RewriteCond ${REQUEST_URI} !^/blog/ RewriteRule ^(.*)$ /blog/$1 [L]
I am trying to rewrite multiple subdirectories to the root directory. The situation I have it that I have one folder namedblog/which would contain the main site folder and also another subdirectory calledprojects/containing other folders which I want accessible from the root:www/ blog/ work/ contact/ projects/ projectA/ projectB/What I want, is to be able to accesswork/,contact/,projectA/andprojectB/from the root directory by going toexample.com/projectAorexample.com/projectBfor example. I would also like theblog/directory to take priority in the case that a folder exists in both.Currently, in my htaccess, I have this, though it just rewrites everything toblog/, removing this from the URL, though not affecting theprojects/folder.Options +FollowSymLinks RewriteEngine on RewriteCond %{REQUEST_URI} !(.*)site RewriteRule ^(.*)$ site/$1
.htaccess - Rewrite multiple subdirectories to root
I'm assuming that you're seeing the404error message in the error log/console for your browser? It should also be displaying theURLthat is returning the404response which, given your request, would be:http://www.mysite.com/available.php.ProblemThe problem is that your ajax call contains a/at the start of theURLparameter. This signifies the root domain of the website (i.e. it points tohttp://www.mysite.com/available.php).url: "/available.php",SolutionSimply change the url parameter to one of the followingcorrectURLsurl: "http://www.mysite.com/php/advert/available.php",ORurl: "/php/advert/available.php",ORurl: "available.php",ORurl: "./available.php",Code for clarification$.ajax({ type: "POST", url: "/php/advert/available.php", data: "city="+city, success: function(response){ alert(response); } });
Quick question I have been working at but can't seem to get it fixed.I have a ajax call but it is not getting a response from the php file, it seems to be loading a 404 instead.The url in the address bar is "mydomain.com/checkcity/"The location of the file with the ajax is "/php/advert/script.php"The location of the php file to be called is "/php/advert/available.php"I am using virtual urls through the use of htaccess.Here is my ajax call:$.ajax({ type: "POST", url: "/available.php", data: "city="+city, success: function(response){ alert(response); } });Here is my htaccess file:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>One thing I noticed is when I search the url in the address bar it will load the php file just not with the ajax call.I am running this currently on Apache 2.2 localhostThanks for any suggestions.
Ajax not finding url
From my understanding of your question, this should work.Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^@(.+?)$ user.php?u=$1 [NC,L]It requires you to have a @ before the username and it passes it as a GET variable (u) However, a person can add other characters which could confuse it as a username./@username/muffinsBut if you want this, and to have pages per username (ie, /@username/info, /@username/about, etc) you can just use theexplode() function in PHP.If you just want it to get the username and nothing else, you can tryRewriteRule ^@([A-Za-z0-9]+)$ user.php?u=$1 [NC,L]Hope this helps! :)
I am making a social networking website, and I can't get this done: If the url ishttp://url.com/@username, I want it to show thehttp://url.com/user?u=usernamepage, but showhttp://url.com/@usernameURL.However, if there is no@in the beginning, treat it like a regular URL.This is my.htaccessfile:Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php [NC,L] RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^/(\d+)*$ ./user.php?u=$1The last three lines are what I tried, however that does not work as I wanted it to. I thought it would work becauseRewriteRule ^/(\d+)*$takes any URI after the slash, and rewrites it to.user.php?u=*, but that didn't work, so I am looking for some suggestions on what to do next.
Twitter Like URL but with a @'s?
For Your URL:http://localhost/ifinal/profile/mynameYou can use like with htaccess:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /ifinal/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^profile/(.*) profile.php?u=$1 </IfModule>If your site not underfolder, use justRewriteBase /And use HTML<a href="profile/<?php echo $uiname; ?>"> <?php echo $uiname; ?> </a>
i'v been stuck with this<a href="profile.php?u=<?php echo $uiname ?>"/>, i'm trying to hide the$_GETvariable but no success. what i'm trying to achieve is something likewww.mywebsitename.com/profile/nameorwww.mywebsite.com/nameinstead ofprofile.php?u=nameis it possible to do so ?
how to hide GET variable from url
If it's allowed in your server you could try something like this for the specific page in your.htaccessfile:RewriteEngine On RewriteRule ^основной-момент.htm$ category.php?slug=ruIn Regex if the character set is enabled on your server you should be able to use the range for the characters:RewriteRule ^([A-Яа-я-]+)\.htm$ category.php?slug=ruTo capture the phrase you would use this (just like English):RewriteRule ^([A-Яа-я-]+)\.htm$ category.php?slug=$1Another way is by detecting the language#For users with Russian as their primary browsing language RewriteCond %{HTTP:Accept-Language} ^ru [NC] RewriteRule .* category.php?slug=ruAdditionally if you're using a dynamic language on the server you should be able to use theREQUEST_URIvar for parsing and determining the intended language as Apache serves the content and programming languages (like PHP or Perl) can do more with parsing.
How do i redirect url with russian slug to specific php page. For example I have this url.http://www.example.com/основной-момент.htmand want to redirect to this one in .htaccesshttp://www.example.com/category.php?slug=<russian slug>
Regular expression to match russian, allow all cyrillic characters in .htaccess
Ifeverythingis belowsubdirectory, you can use a simple rewriteRewriteEngine on # don't rewrite, if it is already rewritten RewriteCond %{REQUEST_URI} !^/subdirectory # only rewrite requests for files below /assets RewriteCond %{REQUEST_URI} ^/assets/ RewriteRule ^.*$ /subdirectory/$0 [L]
I'm using absolute paths to reference assets like css, images and javascript files. So in the<head>ofindex.htmlI have something like this:<link href="/assets/css/style.css" rel="stylesheet">Assuming that my project directory looks like this:- index.html - assets/ -- css/ --- style.cssThis works fine on my local webserver where I set the document root to this directory using a<virtualhost>directive. But when I put this on a webserver's subdirectory (e.ghttp://www.example.com/subdirectory/), it doesn't find the assets anymore when accessinghttp://www.example.com/subdirectory/index.html.How can I solve that without having to use relative paths inindex.html? Can it be achieved with an .htaccess file in the subdirectory? If yes, how?EditThere are other folders on the webserver's root level, that shouldn't be affected by any redirect that occurs for/subdirectory/
How to rewrite absolute assets paths on webserver subdirectory
Just remove everything after the.com:SetEnvIf Referer "^http://sub\.site1\.com/" local_referral SetEnvIf Referer "^http://sub\.site2\.com/" auth_referral SetEnvIf Referer "^http://sub\.site3\.com/" authC_referralSince there's no fence-post for the end of the referer (indicated by the$character) that will match anything thatstarts withhttp://sub.site1.com/etc.
Hi so i have the below working:SetEnvIf Referer "^http://sub\.site1\.com/yvvl/Portal/" local_referral SetEnvIf Referer "^http://sub\.site2\.com/yvvl/Portal/" auth_referral SetEnvIf Referer "^http://sub\.site3\.com/yvvl/Portal/" authC_referral Order Deny,Allow Deny from all Allow from env=local_referral Allow from env=auth_referral Allow from env=authC_referralwhat i dont know how to do is wildcard it so anything from those 3 domains will be accepted my preg is not good at allThanks
Restricting access from only 3 domains in my htaccess fle - SetEnvIf Referer
Playing with your rules, I found out thatHTTP_HOSTincludes the port number. So the rules should look likeRewriteCond %{HTTP_HOST} ^sub.website.com:2000$ [NC] RewriteCond %{SERVER_PORT} ^2000$ RewriteRule ^(.*)$ https://123.45.67.891:3000/$1 [L,R=302]If you want to test against server name alone, you could use%{SERVER_NAME}as @faa suggested in the commentsRewriteCond %{SERVER_NAME} ^sub.website.com$ [NC]
Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed10 years ago.Improve this questionI am trying to usemod_rewriteto basically port forward a port on a subdomain to another port on another IP.Like this:sub.website.com:2000 --> 123.45.67.891:3000How could this be accomplished using a.htaccessfile withmod_rewrite?I have tried the following but to no avail:RewriteCond %{HTTP_HOST} ^sub.website.com$ [NC] RewriteCond %{SERVER_PORT} ^2000$ RewriteRule ^(.*)$ https://123.45.67.891:3000/$1 [L,R=302]
Change port and host using .htaccess [closed]
I've faced the same problem right now and the solution was to change .htaccess content to:FallbackResource /index.phpSo in your case it would beFallbackResource /web/index.phpThis worked for me and I hope someone will find it useful.
I'm using the Silex "micro-framework" for routing purposes of my application. I'm currently stuck on how to rewrite the url with .htaccess.Standard Silex url:localhost/myapp/web/index.php/hello/nameI want it to look like:localhost/myapp/hello/nameWith the following .htaccess code, I'm able to omit the/index.php/part. But I still have to use the/web/part.RewriteEngine On RewriteCond %{THE_REQUEST} /myapp/web/index.php/ RewriteRule ^/myapp/web/index.php/(.*) /myapp/$1 [R=301,L] RewriteCond %{REQUEST_URI} !/myapp/web/index.php/ RewriteRule ^(.*)$ /myapp/web/index.php/$1 [L]Any suggestions? Thanks!
Silex routing .htaccess webroot
In the htaccess file in your document root, add these rules before whatever rules you may already have there:RewriteEngine On # cached copy exists RewriteCond %{REQUEST_URI} ^/images/[0-9]+/(.+)$ RewriteCond %{DOCUMENT_ROOT}/images/cached/%1 -f RewriteRule ^ /images/cached/%1 [L] # cached copy doesn't exist RewriteCond %{REQUEST_URI} ^/images/([0-9]+)/(.+)$ RewriteCond %{DOCUMENT_ROOT}/images/cached/%2 !-f RewriteRule ^ /image.php?id=%1 [L]
Using .htaccess mod rewrite, I would like to rewrite a url, check if that file exists, and if not rewrite again to another url using part of the original url which was removed during the 1st re-write.For example, if the original url is this/images/3001/zebra.jpgI would like to check if the file exists /images/cached/zebra.jpg and serve it if it does exist.And if not I would like to rewrite to /image.php?id=3001Thanks very much, Phil
htaccess rewrite only if file doesn't exist
You should either useRedirectMatchor use mod_rewrite to perform regular expression matching. This should work and would be the shortest and best performing solution:RedirectMatch 301 ^/about /new-about/Domain and protocol are optional - leaving them out like this will keep them as they were, so this is future proof.
I was wondering what would be the correct way to do a redirect like this:Redirect 301 /about/$ http://domain.com/new-about/ Redirect 301 /about$ http://domain.com/new-about/ Redirect 301 /about/me http://domain.com/new-about/That's how I currently do it and it works but I believe there should be a better way?I have 2 pages which are rewrited, one page is a subpage of the other page/about/me/, now both pages should redirect to the new pagenew-about
301 correct way to redirect a directory
I am assuming your site is mainly serving English content, and since utf-8 is compatible with most English language character encodings, I would say this method is rather safe. If not, you need to make according changes for these content.By the way, there is also a global default character set configuration for most HTTP servers, which in theory is more efficient than .htaccess settings. And in most web applications, written by PHP, Java, whatever language it is, it should be best practice for the application itself to clearly state which encoding it is using.For the firefox flashing part, in my past experience with browser development, the browser need to detect your encoding automatically, if it is not stated in response headers. So, if the initial assumed encoding is different with the one detected, the browser need to force the page reflow. Just a roughly guess, for the actual reason, I think the firefox mailing list should be a better place to go.
Very long story, but I had a problem with my site, where there would be a blank white page flashed between any page/link navigation within my site. Only happened in Firefox, and only in newer versions of Firefox (e.g. didn't show up in version 3.6.x).After comparing response headers from two different servers, the site being served from the other server was not having this problem -- I noticed that its response header had this in it:Content-Type text/html; charset=UTF-8My normal server which did have the problem had this in its response header:Content-type text/htmlSo, I added this line to my .htaccess and the problem went away:AddDefaultCharset UTF-8My questions:What is it about Content-Type not having charset specified that could possibly cause Firefox to flash (like 10 millisecond) total blank white screen between pages in my site?Now that I fixed the problem, is my fix "ok"? Is it safe, or does it have some high probability of breaking something else?My quick testing didn't show a problem, but not know knowing what side effects it could cause, or the reason why it fixed my page-flashing problem, bothers me.
is AddDefaultCharset UTF-8 in .htaccess safe?
Are you trying to always remove www or always keep www? This will add it:## Add www RewriteCond %{HTTP_HOST} !^www\. RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] ## CakePHP RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L]
I am using Cakephp 2.0 and my website domain name is www.sample.com , If I try to access sample.com (with out www) then its going to www.sample.com this is fine. But My problem is my domain consists of lot of pages for example :> http://www.sample.com/users/login > http://www.sample.com/users/addIf I access the above url likehttp://sample.com/users/loginthen it redirect to> http://www.sample.com/index.php?url=users/loginbut it needs to redirect tohttp://www.sample.com/users/loginI already written the following code .htaccess file(before the app folder) to redirectRewritecond %{http_host} ^sample.com [NC] Rewriterule ^(.*)$ http://www.sample.com/$1 [R=301,NC]Inside webroot folder I have one .htacces file that contain the following code may be that is the problem I think<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
URL redirecting using .htaccess in Cakephp 2.0
+100Much as I'd like the bounty, I believe this question is a duplicate (ofApplet displays login dialog if basic authentication used). I also believe that there's currently no workaround other than taking the jar file out of the htaccess-protected area of the web site.
I have a Java applet that is being included on a page in a directory that is password protected through a .htaccess file. When browses to pages in this directory I naturally have to authenticate at the beginning of a new session, but the problem is that this Java "Authentication Required" box is popping up on every page load.I thought that maybe putting the applet outside of the password protected directory might fix the problem, but no joy.Any idea what can be done to prevent the "Authentication Required" box from coming up?Thank you!
How to prevent "Authentication Required" box from coming up?
According to Apache documentation, for$N, the value ofNcan only be 0-9. So trying to get$10is not going to work. You will likely need to go through two rewrite steps. So, perhaps you use something like this:RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+/[^/]+/[^/]+)/?$ search.php?country=$1&state=$2&gender=$3&r_city=$4&r_mstatus=$5&r_religion=$6&r_ethnicity=$7&r_cast=$8&r_profession=$8&profession_and_education_and_sort=$9 [NC] RewriteCond %{REQUEST_FILENAME} ^search\.php$ RewriteCond %{QUERY_STRING} ^(country=.*&state=.*&gender=.*&r_city=.*&r_mstatus=.*&r_religion=.*&r_ethnicity=.*&r_cast=.*)&profession_and_education_and_sort=([^/]+)/([^/]+)/([^/]+) RewriteCond ^search\.php$ search.php?%1&r_profession=%2&r_education=%3&sort_by=%4 [NC,L]
I want to get get sort_by in my php code but its seems to be that this is returning value of variable 1 with digit 0.RewriteRule ^abc/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ search.php?counrty=abc&state=$1&gender=$2&r_city=$3&r_mstatus=$4&r_religion=$5&r_ethnicity=$6&r_cast=$7&r_profession=$8&r_education=$9&sort_by=$10 [NC]
Unable to get 10th variable in url string through .htaccess
Try using this rule :RewriteEngine on RewriteRule ^dir/([^/]+)-([0-9]+)$ /dir/$2/$1 [L,R=301]
I'm looking for a regular expression for a .htaccess file where I can redirect one URL to another.URL1: /dir/an-article-title-222URL2: /dir/222/an-article-titleI would like URL1 to 301 redirect to URL2.In highlevel language, I think I want to tell .htaccess to:Take the digits after the last dash (-)Put those digits before the article name with a trailing slash, i.e. 222/Remove the last dash and digits from the article nameAny thoughts, suggestions, code are welcome!
.htaccess regex url redirection
You need to make sure mod_proxy is loaded in your apache config. Without it, thePflag sends the proxy request but there's nothing that can handle the target. It's going to look something like this:LoadModule proxy_module modules/mod_proxy.soThe directory is obviously going to be tweaked to your paths if they are different.Additionally, note that without theLflag in your rule, the proxy request won't be sent back into the processing pipeline until the rewrite engine is finished. So if you have other rules after the proxy rule, they will be applied before the proxy happens.
I have a domain for examplehttp://example.comand another domainhttp://reallylargerdomain name.comI want if sombody accesshttp://example.com/projectsthen server should proxy data from other url. For this i created following .htaccess fileRewrite on RewriteRule ^projects/$ http://reallylargedomainname.com [P]this is not working but when i change it to following it worksRewrite on RewriteRule ^projects/$ http://reallylargedomainname.com [R=301,L]any idea what's going wrong?
proxy a url using mod_rewrite
First thing is to have your .htaccess rules like this:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## If the request is for a valid directory RewriteCond %{REQUEST_FILENAME} -d [OR] ## If the request is for a valid file RewriteCond %{REQUEST_FILENAME} -f [OR] ## If the request is for a valid link RewriteCond %{REQUEST_FILENAME} -l ## don't do anything RewriteRule ^ - [L] RewriteRule ^([^/]+)/([^/]+)/?$ index.php/?node=$1&id=$2 [L,QSA] RewriteRule ^([^/]+)/?$ index.php/?node=$1 [L,QSA]Then make sure to add this line on top of your page between<head>and</head>:<base href="http://mysite.com/">
I want to rewrite my url from:http://mysite.com/index.php?node=home&photoID=10to:http://mysite.com/home/10Currently, for justhttp://mysite.com/homeI useRewriteRule ^([^/]*)$ index.php/?node=$1 [L]however when I try to useRewriteRule ^([^/]*)/([^/]*)$ index.php/?node=$1&id=$2 [L]it doesn't seem to load my pages correctly, the pages aren't styled or anything.(also, the top of my .htaccess file have:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-dand if I just go to mysite.com/home it shows 404 not found. How would I do this if there is not always going to be a sub page?
.htaccess rewrite with sub directories not working
Your rewrite rule logic in plain speak is doing the following:ForANY HOSTother thant www.mysite.co (including foo.mysite.com, blog.mysite.com, etc..)Permanent Redirect (301) tohttp://www.mysite.co/This is the last rule to check in the .htaccess file, so bail outTo not redirect your own subdomains, the easiest and clearest way is to handle it explicitly with more rewrite conditions (see example below). For more kung fu htaccess fun try this:.htaccess Wildcard Subdomains<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www.mysite.co$ [NC] RewriteCond %{HTTP_HOST} !^blog.mysite.co$ [NC] RewriteCond %{HTTP_HOST} !^foo.mysite.co$ [NC] RewriteRule ^(.*)$ http://www.mysite.co/$1 [R=301,QSA,L] </IfModule>
I have the following .htaccess code:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTP_HOST} !^www.mysite.co$ [NC] RewriteRule ^(.*)$ http://www.mysite.co/$1 [R=301,QSA,L] </IfModule>The problem is that all subdomains get redirected to www.mysite.co/subdomain How can I aviod this?
htaccess redirect subdomain
You can useRefererHTTP header to check if a request came from a link on your website (or img src / or iframe src for that matter):RewriteEngine On RewriteCond %{HTTP_REFERER} !example.com RewriteCond %{REQUEST_URI} ^/path/to/protected/page$ RewriteRule . - [F]Whereexample.comis your domain name, and/path/to/protected/pageis the paht you want to protectHowever, note that this approach can be fooled, as HTTP headers can be constructed by remote user (treat http headers as user input - do not trust them ;) )
I have a site made with iframes. I have a page I want to show in my own iframes, but I want to deny direct access. How can I protect it that way in my.htaccess?
How to use .htaccess to allow page access in my iframe but not directly?
Your configuration should work. When modifyinghttpd.confyou need to restart apache No need for restart when modifying.htaccess.Just in case, try to add the '[L]' flag to the Rewrite Rule in thehttpd.conf, so it stops processing more rules after that match.
I'm trying to get backbone.js's router to work with my XAMPP apache server on localhost.I need to prevent apache from evaluating the directory paths that are supposed to go to the router and just forward everything to/test_backbone/index.html. I've tried everything that I could find, nothing works.Currently, I have this in httpd.conf file:# html5 pushstate (history) support: <ifModule mod_rewrite.c> Options +FollowSymLinks IndexIgnore */* # Turn on the RewriteEngine RewriteEngine On # Rules RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) /test_backbone/index.html </ifModule>I've also tried this:# html5 pushstate (history) support: <ifModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !index RewriteRule (.*) index.html [L] </ifModule>I was under the impression that some of those lines are supposed to say to load the static file if it exists, but none of my javascript files are being loaded, everything just goes back to/test_backbone/index.htmlI've also tried.htaccessfiles. For all I know I'm not even putting this code in the right place.Any help would be greatly appreciated!
Backbone.js router using pushstate with XAMPP apache server on localhost
Your redirect happens whenever a request is made to the exact domainmydomain.com(that's what the RewriteCond is testing for). It doesn't apply to any other domains and doesn't detect HTTPS. Use this instead:RewriteEngine On RewriteCond %{HTTP_HOST} ^(www.)?mydomain.com$ RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
I am trying to force HTTPS on a domain. It must be done using a method that works by domain name and not port number (due to host structure/setup).My closest attempt was:RewriteEngine On RewriteCond %{HTTP_HOST} ^mydomain.com$ RewriteRule ^.*$ https://www.mydomain.com/$1 [R=301,L]This works when typing "mydomain.com" into the address bar, automatically redirecting to "https://mydomain.com" but when I type "www.mydomain.com" it does not work. I assume it is a syntax issue as I am very new to htaccess and have spent about 4 hours trying to create a solution from other's code.Any chance of a pointer?To make the setup a little more understandable./public_html/- All files in this folder relate towww.mydomain.com/public_html/subfolder- These folders contain files also relating tomydomain.com/public_html/subdomain- These folders contain files relating towww.myotherdomain.comMy other domains are subdomains ofmydomain.comfor to be listed in the cpanel on the host.For example:subdomain.mydomain.comis the same aswww.myotherdomain.com.Hopefully that clears up the structure.
.htaccess forcing HTTPS
You will need to use the following:setenv.add-response-header = ( "Content-Disposition" => "attachment" ) setenv.add-response-header = ( "Content-Type" => "application/octet-stream" ) setenv.add-response-header = ( "Content-Transfer-Encoding" => "binary" )I imagine you are trying to force file downloads as opposed to displaying the file in the browser? If this is the case you only need the application/octet-stream MIME-Type as per RFC 2046 (https://www.rfc-editor.org/rfc/rfc2046)'The recommended action for an implementation that receives an "application/octet-stream" entity is to simply offer to put the data in a file, with any Content-Transfer-Encoding undone, or perhaps to use it as input to a user-specified process.'
I have started to use Lighttpd and I have this.htaccessfile which alters the response headers.<IfModule mod_headers.c> Header unset Content-Type Header unset Content-Disposition Header set Content-Disposition attachment Header set Content-Type application/octet-stream Header add Content-Type application/force-download Header add Content-Type application/download Header unset Content-Transfer-Encoding Header set Content-Transfer-Encoding binary </IfModule>How can I translate this to work in Lighttpd?
Translate Apache .htaccess to Lighttpd and mod_headers
What you basically want to do, is start with this tutorial:http://www.alistapart.com/articles/hotlinking/This shows you how to redirect images that come from external sites to a PHP page. Then, you can use that PHP page to watermark your image, with something like this:<?php header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($_GET['pic']); $size = getimagesize($_GET['pic']); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?>
I want to know if it is possible to protect images in my host that are loaded from outside by adding a watermark using.htaccess?That is, if another site uses my image URLhttp://example.com/1.jpgin a img tag in their own websites.The plan is the when a foreign request comes to my host, I add a watermark to it and send it to the user browsing the foreign site.
Htaccess and watermark
You can execute this command withsystemorexecto add your users.I've created a code snippet that might work for you:<?php define('HTPASSFILEPATH', '.htpasswd'); function addUser($pUser, $pPass) { exec("htpasswd -cb " . HTPASSFILEPATH . " ${pUser} ${pPass}"); } ?>And remember, thehtpasswdtool should be in yourPATH
I know that it's possible to add new HTTP auth credentials through this shell script:htpasswd -c .htpasswd testingIs it possible to achieve the same with a PHP script? I know I could use a regular PHP auth system, but that's not what I'm looking for.
Create new HTTP auth credentials using PHP instead of shell
Here's what you have to do:RewriteEngine On RewriteRule ^([a-z0-9_\-]+)\.([a-z]+)$ _images/$1.$2 [NC,L]by using NC (case insensitive) you don't need to put A-Za-Z and L means the last rule in case you have other rules after this one.
Basically I'm using htaccess I have a hidden directory which I'd rather not be used and I want shorter links:I would likehttp://example.com/12940.pngto gotohttp://example.com/_images/12940.pngHere's my rule:RewriteRule ^([A-Za-z0-9\_\-\/]+).([A-Za-z]+)$ "_images/$1.$2"What's wrong with it, I get 500.
Redirecting to a photo with htaccess
Here's what you can do:RewriteEngine ON #domain.com/episodes/ShowName_Season_1_Episode_3_The_Title_Of_The_Episode.html RewriteRule ^episodes/([a-z0-9\-]+)_Season_([0-9]+)_Episode_([0-9]+)_(.*)$ episode.php?s=$2&e=$3 [NC,L] #Even more SEO friendly: http://domain.com/ShowName/Season/3/episode/4/title/ RewriteRule ^episodes/([a-z0-9\-]+)/season/([0-9]+)/episode/([0-9]+)/(.*)/? episode.php?s=$2&e=$3 [NC,L] #or Even more SEO friendly: http://domain.com/episodes/ShowName/season-3/episode-1/title RewriteRule ^episodes/([a-z0-9\-]+)/season\-([0-9]+)/episode\-([0-9]+)/(.*)/? episode.php?s=$2&e=$3 [NC,L]I don't recommend to use "_" for SEO but "-"
So here's the deal:episode.php?s=1&e=3brings up information for season 1 episode 3.So make it SEO friendly I want to be able to have users be able go to the following:domain.com/episodes/ShowName_Season_1_Episode_3_The_Title_Of_The_Episode.html(or without the .html, doesn't really matter).This is what I have so far:RewriteRule ^episodes/([a-z0-9-]+)_$_([a-z0-9-]+)_$_([a-z0-9-]+).html episode.php?s=$1&e=$2I know this is not right...how can I make it take the two numbers in the rewritten URL and associate them with PHP GET variables in the actual URL?I know how to do more basic mod_rewrites but this one has been confusing me. I am guessing it is something stupid, so thanks in advance for your patience.
Mod_Rewrite with multiple PHP variables and dynamic text
Use this .htaccess in the root folder:# Enable mod_rewrite RewriteEngine on # ^: Start with # folder1: name the folder # (\/?): Can containt an ending slash eg: folder1/ or folder1 # $: End with # [QSA]: Query string append, means you can use %name=value # [NC]: Non Case: Case insensitive # [L]: Last rule, stop if this rule match the url RewriteRule ^folder1(\/?)$ /index.php [QSA,NC,L] # (.*): Everything # $1: the matching filename- file must exists. RewriteRule ^folder1/(.*)(\/?)$ /$1 [QSA,NC,L]
I am new to htaccess and have some problem for which I need help. In my site I have a folder(which is blank actually) for which I want to serve content from the root folder.Lets say the structure is as below:example.com-folder1 -index.php -anotherpage.php -.htaccessSo, when someone go to example.com/folder1/index.php he will see the url as that but get content from example.com/index.php. If he visit example.com/folder1/anotherpage.php he will get content from example.com/anotherpage.php. Ofcourse, when he visit directly to example.com/index.php he will see example.com/index.php.I found many example which shows the opposite but not as I want. Also to clarify, I want to rewrite, not redirect so the url will fake that there is are actually pages in folder1.Any help will be appreciated.
htaccess rewrite folder url to show content from root folder
Yes, the L flags do not work the way you think they do in that example. Because the .htaccess file is in the "per directory" context, mod_rewrite creates a subrequest process. That process will keep processing rules until it can not process anymore, or it is interrupted as in your example with L flag.However, because a rewrite was triggered via rule #1, the rewrite engine will create a new subrequest and go through the .htaccess rules again. It repeats this process so long as a rewrite occurs, and only passes processing on when there are no rewrites.In your example, the L flags are not only not doing what you thing they are, they are actually making things slower by requiring apache to create multiple subrequests, rather than using a single subrequest that handles both the rules and then completes.
This is a trivial question but I wanted to double check.How many times is the following.htaccessrun through?RewriteRule ^.*$ bla [L] RewriteRule bla foo [L]The[L]as I understand stops executingRewriteRule's for the rest of the file, but does it then start all over again?This may seem like a dumb question, so I apologize in advance, but in my very limited experience with writingRewriteRule's I've gotten the feeling that the.htaccessfile is sometimes parsed more than once.
How many times is .htaccess parsed and the RewriteRule directives run?
I got it to work on my own! Here's the rules if someone else needs to make the same thing:RewriteEngine On RewriteBase / ## Check if its not a filename or dirname RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ## Rewrite rules RewriteRule ^(.{2})/(.*)$ index.php?lang=$1&page=$2 [L] RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
I have a bit of a dilemma with mod_rewrite.How do I write a rule that will decide the following:If i browse/en/page/pageI want to rewrite this to:index.php?language=en&page=/pageBUT if i browse just/pageI want to rewrite this to:index.php?page=/pageIs this possible?Edit:/page is just a random dynamic pagename, it could aswell bewhatever.I need a rule that checks like /se == a string, and not longer than 2 characters>/page --> index.php?lang=se&page=/page and if browsing page /page it will notice that /page == longer than 2 characters and rewrite to index.php?page=/pageEdit2: Found the anser to my question:RewriteEngine On RewriteBase / ## Check if its not a filename or dirname RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d ## Rewrite rules RewriteRule ^(.{2})/(.*)$ index.php?lang=$1&page=$2 [L] RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
PHP/Apache: Rewrite rules with .htaccess
As I explained in :How does url rewrite works?every rewrite triggers a new call to the rewritten URL. (HTTP 3xx code).So the client will ask forwww.site.com/this/is/path/to/hide/page.php, would be redirected towww.site.comand will be served the index page as a normal user.There is no way to tell the client to display one URL in the browser bar instead of another, client browser will always make a new request. (Or you could impersonate any site for example)If you are not against the use of a cookie, or can use environment variable you may be able to do something like :RewriteRule this/is/path/to/hide/page.php / [co:knowHiddenPath=true]The environment variable as same syntax withEinstead ofco.(Seehttp://httpd.apache.org/docs/2.0/mod/mod_rewrite.htmlfor cookie information)Your index page should then check this cookie/variable to serve the hidden page or not.Another solution would be to enable access with password to your file. So even if someone know the URL he would not access the file. Security by obscurity is does not exists.
i need to hide full path and show shortly:www.site.com/this/is/path/to/hide/page.php-->www.site.comAny idea to do it with.htaccessapacheandrewrite rules??EXAMPLE:If i typewww.site.comi want openindex.php(in /),but if i go to/hidden/pathi want to openfile.php(in hidden/path)mantaining browser url in www.site.com.EDIT:i want to see in the browser barwww.site.comand i want to open page at/this/is/path/to/hide/page.php.thanks
Rewrite rules to hide an url
I think you wantIndexOptions +SuppressHTMLPreamble.From theApache mod_autoindex docs:If the file specified byHeaderNamecontains the beginnings of an HTML document (<html>,<head>, etc.) then you will probably want to setIndexOptions +SuppressHTMLPreamble, so that these tags are not repeated.
I'm trying to pretty up the default directory view in apache with an htaccess file. I've done pretty much everything I want to do, except change the default verbiage for the title. By default, it says something like:"Index of [folder_name]"and if I use this:# SPECIFY HEADER FILE HeaderName /apache/header.htmlin htaccess, I can include my own header title, which I like because I can add CSS styling and whatnot, but I cannot make the title change with each folder I visit. Is there a way to do this?
editing the default title for directory views in apache with htaccess
There's also theFollowSymlinksoption in Apache, which is generally disabled by default. You can enable it by doingOptions +FollowSymlinks
I have a folder in my root MAMP directory, "site". I have that symlinked to a folder in ~/Documents/Dropbox/site, so whatever happens in "site" gets transferred to Dropbox.However, when I do this, I get a 403 forbidden error when trying to viewlocalhost/site- is this a problem because I'm using PHP and I should fix php.ini, or is this an httpd.conf problem?In httpd.conf, I haveAllowOverrideset toNone.Thanks for any answers in advance.
Symlinked MAMP Folder Causing 403 Forbidden
I seem to be answering this question a lot lately... Look, if you don't want something accessed by URL, you don't need to use .htaccess, or PHP. Just don't put it inside the document root at all.Seemy answer here, which explains the structure you should use. You can then use PHP to download it; myanswer hereexplains how to download a file with PHP. Doing things this way is easier to maintain, easier to implement and more secure.Note that this doesn't just apply to images, etc, but also to your PHP libraries and whatever else. Generally, I have one PHP file (e.g. index.php) in the document root, a little bit of CSS, JS and a few images. Everything else should generally be somewhere else.
Here's the URLhttp://www.website.com/uploads/pvtimages/image.pngI don't want the image to be displayed to anybody, not even to me but can be downloadedi...e<a href="http://www.website.com/uploads/pvtimages/image.png">Download</a>i..e only from a specific page (download.php)I want all images in that folder to be protected.Is it possible?? using php or .htaccess or both?
Is there any way to block image from getting displayed
Options -Indexes <Files *> deny from all allow from 213.106.26.195 allow from 213.106.15.132 Options +Indexes </Files>I used directive because I tried it in .htaccess, but in your server profile you can use the directive as well, of course.
i need to limit the directory listing for all users except certain IP's. Any idea how to do that?the option for it should be:Options -Indexesand let's say the directory i need to restrict is /restricted/<Directory /restricted> Options -Indexes </Directory>but how to place the IP restriction for all but, for instance, 127.0.0.1Any help will be greatly appreciated
Apache directory listing restriction per IP bases
Try thismod_rewriterule in the .htaccess file in the document root ofoldsite.olddomain.example:RewriteEngine on RewriteRule !^myspecialdirectory($|/) http://newdomain.example%{REQUEST_URI} [L,R=301]
I am trying to move my current site over to a new domain, except for ONE directory.Example:current site: oldsite.olddomain.examplenew site: newdomain.exampleSo I know I can create an .htaccess redirect entry to do this, and it works, but I want ONE exception - I do NOT want to redirect a specific directory. I still want this to work:http://oldsite.olddmain.example/myspecialdirectory/…and every file and directory under it.Can someone help? Thanks!
Redirect entire site except one directory to a new site - apache .htaccess
The problem is the file index.php is in the same directory as htaccess and is included and handled by the rewrite. Try adding rewrite conditions:RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-dAlso, the input you are passing to the id paramater is very insecure. Assuming you use numeric ids, you may want to use[0-9]instead of a.to ensure only numbers are passed. If they are alphanumeric, you would still want to use something like:[a-zA-Z0-9\-_].
I'm trying to do the basic mod_rewrite clean URL trick, where/category/itemrewrites to/category/index.php?id=item. In the/categorydirectory, I have this in my .htaccess file:Options +FollowSymLinks RewriteEngine on RewriteBase /category/ RewriteRule ^(.+)$ index.php?id=$1 [L]It sends the request to theindex.phpscript just fine, but instead of finding "item" in the id variable, I'm getting "index.php". That is,/category/itemseems to be rewriting to/category/index.php?id=index.php.I've tried endless variations, with different/no RewriteBase and other changes, but nothing is working. Any idea where I've gone wrong?
Rewrite redirects the simple regex to base file
Add this before the last rule:RewriteBase / RewriteCond %{HTTP_HOST} !="" RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301]or to deny access:RewriteRule ^index.php(/.*)?$ - [R=404]
I created a CodeIgniter application and now I'm trying to redirect the urls with index.php to urls without it.My current .htaccess is:RewriteEngine On RewriteBase / # Removes trailing slashes (prevents SEO duplicate content issues) RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ $1 [L,R=301] # Enforce www # If you have subdomains, you can add them to # the list using the "|" (OR) regex operator RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC] RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301] # Checks to see if the user is attempting to access a valid file, # such as an image or css document, if this isn't true it sends the # request to index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]The only problem is that the same page is accessible with and without the index.php.For example:http://www.plugb.com/index.php/games/adventure-rpgandhttp://www.plugb.com/games/adventure-rpgIs there a way to redirect the index.php URLs?Thank you, Gabriel.
Redirect index.php in CodeIgniter
If you have mod_rewrite this should work:RewriteEngine on RewriteRule ^$ /index/index.php [L]That will only match / (which it sees as empty) and internally redirect to /index/index.php
I have a site that is arranged thus:/about/css//index/index.php/js//index.phpindex.php uses a PHP redirect to index/index.phpI want to create a .htaccess rewrite rule so that when the root is accessed, /index/index.php is displayed BUT /about etc. stays the same.
.htcaccess redirect ONLY root ("/") to sub folder
To others looking at this, and using a local server with virtualhost directives: took me a while, and none of the methods found online worked (probably because my MAMP apache version is not 2.4 yet or something), but this one did.Forget about adding 'conditional' lines to your .htaccess file: you can define which .htaccess file to use in your virtualhost setting!So just create a file .htaccess_dev, and add this line to your virtualhost definition on your local / dev machine:AccessFileName .htaccess_devSo it becomes something like this:<virtualhost> ServerName www.example.local DirectoryRoot /var/www/www.example.local AccessFileName .htaccess_dev </virtualhost>
My local development PC is set up to use PHP5 by default, my client's host (1and1.co.uk) is set up to use PHP4 by default.To enable PHP5 on a 1and1 account, you must add the following line to your .htaccess file:AddType x-mapp-php5 .phpIf I add this line to my local .htaccess file, it breaks my PHP.How do I add this line conditionally based on the domain (or some other parameter?) so it is only executed by the live site and not my dev site?I'd like to be able to just upload (FTP) my entire source tree without worrying about having to remember to edit the .htaccess on the server ever time.e.g.<IfDomain www.example.com> AddType x-mapp-php5 .php </IfDomain> ... rest of .htaccessIs this possible?I don't have access to the server config file, only .htaccessThanks in advance.
How do I conditionally add a line to Apache .htaccess based on the domain?
I doubt you'll be able to get your subdomain to function outside of your public_html folder (although I'm no server admin). Typically that requires DNS modifications or tweaking the server's configuration. Have you tried making a sub-directory and rewriting calls to the subdomain? For example this placed in the .htaccess within your public_html directory:RewriteCond %{HTTP_HOST} ^subdomain\.example\.com$ RewriteRule (.*) /subdomain/$1 [L]I'm not sure if that would work (never needed to test it myself), but it's more likely to function than trying to target files that live outside the directory specified by the webhost as the location of your domain's files.Good luck!
Hey, My host is absolutely terrible. For some odd reason creating a subdomain in cPanel simply does not work, and their support lines are always busy. I thought I could get around this by using .htaccess. I'm sure it's not that hard, but I'm kind of new to mod_rewrite and have had little success searching in the last 5 hours. Heres the situation:/home/user/public_html automatically redirects tohttp://www.example.comSince I'm using a CMS in public_html it has already added the rule in .htaccess to redirect anything unfamiliar after example.com/ to a 'Page Not Found'/home/user/subdomain needs to redirect tohttp://subdomain.example.comHow should I go about creating a subdomain redirection to an absolute path? Or How can I add an exception in my .htaccess
Creating SubDomains to Absolute Paths with .htaccess
I would think your example would cause an endless loop since /index.php matches what you are doing. Try this:RewriteRule ^([A-Za-z0-9]+)/?$ /index.php?folder=$1 [L]If you want it to work for all directories that exist, this will probably work as well.RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+)/?$ /index.php?folder=$1 [L]
I just want to get a quick htaccess redirection. ie:domain.com/subfolderGreen --> domain.com/index.php?folder=subfolderGreen(note that the subfolderGreen actually exists)I've been trying but couldn't get to the regex needed.thanks. a.ADDED:Sorry, i want this to work for any subfolder, not just "subfolderGreen" I'm usingRewriteRule ^/([^/]+)/?$ /index.php?folder=$1 [L]but it's not working. any clues?
htaccess (no redirection) [REWRITEURL] (folder to index.php)
Try this:RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com RewriteRule ^(.*)$ http://example.com/$1 [R=301,QSA,L] RewriteCond %{REQUEST_URI} !^/(wiki|blog|style|forum) RewriteRule ^(.*)$ http://www.example.com/forum/$1 [R=301,QSA,L]
I'd like to redirectwww.example.com/*toexample.com/*Andat the same timeredirectexample.com/*toexample.com/forum/*But I also have/wiki/and/blog/and/style/, so Idon't wantto redirectexample.com/style/*toexample.com/forum/style/*This is what I have at the moment, which is not working quite correctly:Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^example\.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/forum/ RewriteRule ^(.*)$ forum/$1 [R=301,L]Clarification: my question can be asked in a simpler way.I'd like to redirect anempty REQUEST_URIor/, or anon-existent file only if it is in the root directoryto/forum/.
.htaccess rewrite without www AND redirect to subdirectory
Could you please try following Rules, written based on your shown samples. We need to useRewriteCondhere to check from which domain(host) name request is coming from and then accordingly redirecting request from bal.... to thelasdancer domain.RewriteEngine ON RewriteCond %{HTTP_HOST} balletforadults\.com [NC] RewriteRule ^resources/?$ http://thelastdancer.com/blog [R=301,L]
I am trying to permanently redirect an entire site, where approx. 130 links remain the same except for the new domain, and then approx. 20 links have to be redirected by file name. I cannot get code to do both.I have this beginning on the first line of my htaccess page:RewriteEngine on RewriteRule ^resources$ http://www.thelastdancer.com/blog? [R=301,L] RewriteRule ^(.*)$ https://thelastdancer.com/$1 [R=301,L]I can get the second rule to work - all my articles redirect perfectly when the /pagetitle matches. I cannot get the singe pages to redirect:https://balletforadults.com/resourcesSHOULD OPEN TOhttps://thelastdancer.com/blogI have also tried putting the first rule in the second position, no luck.Thanks for any guidance - I have been searching through mountains of redirect code, and can't get anything to work.
Can I use .htaccess rules using wildcard for site, followed by rewrites for specific pages?