Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
Nope.Reason is any rules you put in your htaccess file will only get appliedonce the request has been made, which means it'll only get applied once thehttps://localhost/request is made. If there's nothing listening to the HTTPS port (443) on localhost, then the rules will never get applied.If port 443islistening for requests on localhost, but it's just a matter of lacking an SSL certificate, the rules still won't get applied untilafter the SSL handshake is performed, which means, you're still going to get the security warning about your certificate.That being said, the rules you'd want if you had apache listening to port 443 and have a certificate installed is this:RewriteEngine On RewriteCond %{HTTP_HOST} ^localhost$ [NC] RewriteCond %{HTTPS} on RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R]
I'm working on a website locally that contains https links, so when I click on one of these links it takes me tohttps://localhost/...which doesn't exist as there is no SSL certificate installed.Is there anything I can add to.htaccessthat checks if I'm on localhost and if so redirectshttpstohttp? The .htaccess file is used in both local development and production on our server so anything I add mustn't affect the live website.
Redirect HTTPS to HTTP on localhost only
Change your rules to this:RewriteEngine on RewriteBase / RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
The main site at www.mydomain.com is set up as a secure site using an SSL certificate.I need to create a subdomain that is not secured (http://open.mydomain.com).I'm hosting with InMotionHosting.com. I've created the subdomain in cPanel and pointed it to the folder at public_html/open (the main site is at public_html/mainsite) but when I try to visit the subdomain URL I get an SSL error in Chrome, and in IE I get redirected tohttps://www.mydomain.com/open.How do I fix this?Here is my .htaccess file:RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I need to force ssl on main domain but not subdomain
You can have these rules in your document root .htaccess:RewriteEngine On RewriteCond %{THE_REQUEST} \s/+([^.]+\.php)\?lang=([^\s&]+) [NC] RewriteRule ^ /%2/%1? [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([A-Z]{2})/(.+?)/?$ /$2?lang=$1 [L,QSA,NC] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([A-Z]{2})/?$ /?lang=$1 [L,QSA,NC]
I have a multi language php script which use URLs to detecting which language files should be load from template folder for user.for example:English version:site.com/etc.phporsite.com/etc.php?lang=ENArabic version:site.com/etc.php?lang=ARbut I want to have more pretty and also SEO friendlier URLs. So I need to detect language by a nicer way from URLs.for example:English version:site.com/EN/etc.phpArabic version:site.com/AR/etc.phpis this possible by .htaccess file? (I search for solutions in stackoverflow, but it didn't work...)Thank you Amir
Friendly php URL for multiple languages using htaccess file (detect language from URL)
I want to set http 410 for everything on the domainYou can use this rule as yourfirst rulein yourDOCUMENT_ROOT/.htaccessfile:RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^ - [L,R=410]Don't forget to replacedomain.comwith your actual domain name.
We have a number of websites that have now been closed down and deleted however are still indexed in Google, even though they are returning a 404.I want to set http 410 for everything on the domain, how would I do this in the htaccess? Use wildcards?
How do I set 410 for entire website?
put this code in yourDOCUMENT_ROOT/.htaccessfile:RewriteEngine On RewriteBase / RewriteRule ^es/(blog/.*)$ /$1 [L,NC,R] RewriteRule ^blog/(.*)$ /es/$1 [L,NC]
i have the example website:example.comi have a blog folder on this website and i also have another folder with the exactly same files as the root(its a translated folder)example.com/en/I need to redirect users that click on my banner to the root blog folder, using the same atributes as he clicked.for example:he clicks on a blog post in the /en/ folderexample.com/en/blog/eventos_21_example-posti need to add something on htaccess to redirect this link toexample.com/blog/eventos_21_example-postIt needs to be something that works for every post.Any help?Thank you
htaccess to redirect to another directory
The issue is triggered by usingPHP as a CGI Wrapper.If PHP is running as mod_php apache module it's not prefixing your variables.Reason for that is internal redirect handling thus apache recreates the variables with the REDIRECT_ prefix :-/Solution (updated)Use PHP-FPM or mod_phpIf you wanna use CGI Wrapping for PHP put this into your .htaccess:RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
I'm setting an environment variable in an htaccess file and it's being prepended with "REDIRECT_". As far as I've read, this is caused by URL rewriting.. the thing is, I'm not doing any rewriting (that I'm aware of).My webspace contains two files:.htaccessSetEnv Foo "bar"index.php<?php print_r($_ENV);Now, I'mguessingthis may have something to do with the fact that this is on a shared hosting package with 1&1.. is there anything else I should be checking or has anyone experienced this before? Or am I just missing something??Cheers
htaccess SetEnv REDIRECT_ prefix
You're getting authentication dialogue twice because Apache runsmod_authdirective beforemod_rewritedirective. Alsoauthenticationsession set in HTTP URL isn't valid in HTTPS URL anymore therefore it Apache has to follow the BASIC auth directive under HTTPS as well.There can be somework-aroundtype solutions to skip BASIC auth for http URL and do it only for HTTPS but it is not straight forward.UPDATE: Here is a workaround solution that you can use to avoid showing BASIC auth dialogue twice.RewriteEngine On RewriteBase / # redirect to HTTPS and set a cookie NO_AUTH=1 RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,CO=NO_AUTH:1:%{HTTP_HOST}] # If cookie name NO_AUTH is set then set env variable SHOW_AUTH SetEnvIfNoCase COOKIE NO_AUTH=1 SHOW_AUTH # show Basic auth dialogue only when SHOW_AUTH is set AuthType Basic AuthName "example.com" AuthUserFile /www.example.com/web/content/.htpasswd Require valid-user Order allow,deny allow from all deny from env=SHOW_AUTH Satisfy anySince cookie is only set forhttp://domain.comtherefore env variable is also set only once andBASIC auth dialog is also shown only once.
I am trying to protect my website with a directory protection code. The website is in PHP.My website has https and it is likehttps://www.example.com.When I Open the website it is asking for username and password twice. I think it is taking once for http and once for https.Can anyone please help me how to solve this problem.Below is my.htaccess file codeoptions -multiviews <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^www.example.com$ [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] </IfModule> AuthType Basic AuthName "example.com" AuthUserFile /www.example.com/web/content/.htpasswd Require valid-user <IfModule mod_security.c> # Turn off mod_security filtering. SecFilterEngine Off # The below probably isn't needed, # but better safe than sorry. SecFilterScanPOST Off </IfModule>Thanks in advance for any help.
Directory protection asking for password twice on my https website?
You have a few options.1 -Basic Authentication- When a user does a request, apache checks for htaccess file and when basic auth is set, it returns a header for authentication (when no login info has been sent). The webbrowser reacts on that and gives a native login screen. This screen is very well supported by all browsers and password remember tools. When entering the credentials the next requests sent the credentials (unencrypted) each time, so apache doesn't gives the login screen each time. You can read more on ithereHow to set it up, create .htaccess file:AuthName "Protected" AuthType Basic AuthUserFile securepath/.htpasswd Require user authuserCreate the .htpasswd at the command line:$ adduser authuser $ passwd authuser $ htpasswd -c securepath/.htpasswd authuserBut many control panels have tools to set this up using an interface.2 - Own system - You could write your own auth system where in your code you validate whether a user is authorised or not. You can build a login screen where the user when granted gets a cookie that represents the user on your server. But the cookie itself is unencrypted and can be read by others.The latter gives you the option to the user to have different passwords more easier. And the password isn't sent each time, only the cookie.For security I advise using SSL/HTTPS connection where everything is encrypted.
I really don't get it. I don't understand how .htaccess, php and HTTP work together within the topic http-authentication.how can this be achieved: I have a folder where i want to prevent access to unauthorized people. in this folder i have images, for example, and if the user is authorized, the image should be displayed, if not he should get the possibility to enter a username and password for this one request.do i need an .htaccess file, that redirects to a php file, that checks and handles the authentication and sends appropriate headers and also outputs the requested file?or must i do something else? am i to solve this completely different?
How exactly does HTTP Authentication with PHP work?
Insert this rule before existing rule to removeindex.phpfrom URI:RewriteCond %{THE_REQUEST} /index\.php [NC] RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
I have the following code in my .htaccess file.RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]This redirects all requests to index.php. However I am still able to access www.mydomain.com/index.php directly from the URL. As www.mydomain.com servers the same content as www.mydomain.com/index.php will this be recorded as duplicated in google, if so how do I prevent it.
Redirecting all requests to index.php without direct access
You just need thissingle rulein theDOCUMENT_ROOT/.htaccessfile of olddomain:RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] RewriteRule ^ http://%1newdomain.com%{REQUEST_URI} [R=301,L,NE]Explanation:NC- ignore caseL- LastR=301- Send301status to browserNE- no escaping%1- is the value we capture in first(...)inRewriteCond. That will be eitherwwwor blank
Essentially I need an .htaccess file that will redirect all traffic to our new domain. It need to work in the following conditions:http://www.olddomain.com/path/file.php => http://www.newdomain.com/path/file.php https://www.olddomain.com/path/file.php => http://www.newdomain.com/path/file.php(note in the above case the https redirect to http - this is not an issue)Also:http://olddomain.com/path/file.php => http://newdomain.com/path/file.php https://olddomain.com/path/file.php => http://newdomain.com/path/file.phpI've almost got it working by first redirecting the https version of www.olddomin.com to http version ofwww.olddomain.comwhich then redirects to the http version of the new domain, the problem I have is with the non-www version ofhttps://olddomain.comwhich redirects tohttp://olddomain.comand then stops.The code I am using is:RewriteEngine On RewriteBase / RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]This almost works except thathttps://olddomain.com/path/file.phpjust redirects tohttp://olddomain/path/file.phpand stops and doesn't get redirected tohttp://newdomain.com/path/file.phpAny help would be appreciated.
.htaccess redirect to new domain with path intact for both www and non-www as well as https and non https
This turned out to answer my own question:RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ application/index.php?url=$1 [QSA,L]If the URL doesn't exist, it loads the index.php file inside of the folder "application", and it keeps the URL the same, which was exactly what I needed...Thanks for the answers!
My question might be dumb, but I googled it and didn't find an answer...Let's say I want to access my website in this given url: www.mywebsite.com/something/something_else/?some_query_string=true (I put the query string because it is going to be there, and I don't know if it makes any difference in the htaccess file)I want it to keep the URL the same, but load the index file for no matter what URL, which is not in the root of the server. My server has an "application" folder, where all the code is.How can I do this?Thanks!
Keep URL the same, load index.php
The issue actually had nothing to do with WordPress. After recently upgrading to Plesk 11.5 there is an option in the domain's "Hosting Settings" that was wrong. The setting is called "Preferred domain".Preferred domain:Regardless of the domain's URL that visitors specify in a browser (with the www prefix or without it), a page with the preferred domain's URL opens. The HTTP 301 code is used for such a redirection. The 'None' value means that no redirection is performed.For some reason it defaults to "domain.tld" but it should be set to "None". This fixes the problem instantly and now WordPress does not go into a redirect loop.Here are the steps to change it:Go to your domain nameClick on "Websites & Domains"Click on "Hosting Settings"on the domain nameFind "Preferred domain" and select "None"
I recently launched 3 new WordPress sites and for some reason they are all getting redirect loops. Going towww.example.comredirects toexample.com. On one of them I have just decide to stick with the non-www since it was a brand new site, however the others I need to force the www.So far I have tried the following:Changing.htaccessto force www — Did not workDefining my blog & site url inwp-config.php— Did not workUpdated database changing fromwww.example.comtoexample.comand the back towww.example.comjust trying to reset it — Did not workI've never experienced this issue before until recently.
WordPress sites keep redirecting to no-www
Is it possible to use multiple htpasswd's in this way or is there a better/cleaner solution to use only one htaccess and only one htpasswd?Something that you could do is keep on htpasswd file, and instead of usingRequire valid-user, use the require with a specific username:<Files "leiden.html"> AuthName "Name and Password" AuthUserFile /var/www/fullpath to/.htpasswd Require user aaa AuthType Basic </Files> <Files "alkmaar.html"> AuthName "Name and Password" AuthUserFile /var/www/fullpath to/.htpasswd Require user bbb AuthType Basic </Files> <Files "vlaardingen.html"> AuthName "Name and Password" AuthUserFile /var/www/fullpath to/.htpasswd Require user ccc AuthType Basic </Files>The mod_authz stuff (htpasswd/BASIC auth) isn't what's causing IP addresses to be blocked. Something else must be causing that.
I protected a couple of pages via the htaccess and htpasswd. Until now the site functioned well, but the last couple of days, we're experiencing some problems, and i wan't rule out this part of code.My htaccess:<Files "leiden.html"> AuthName "Name and Password" AuthUserFile /var/www/fullpath to/.htpasswd Require valid-user AuthType Basic </Files> <Files "alkmaar.html"> AuthName "Name and Password" AuthUserFile /var/www/fullpath to/.htpasswd2 Require valid-user AuthType Basic </Files> <Files "vlaardingen.html"> AuthName "Name and Password" AuthUserFile /var/www/fullpath to/.htpasswd3 Require valid-user AuthType Basic </Files> ErrorDocument 401 /error401.htmlAnd the corresponding htpasswd's containing the encrypted name and password combination..htpasswdaaa:bbbb.htpasswd2ccc:dddd.htpasswd3eee:ffffIs it possible to use multiple htpasswd's in this way or is there a better/cleaner solution to use only one htaccess and only one htpasswd?For some reason, the site regularly blocks a user's ip-adress as a safety-precaution and i want to rule this security-solution out as cause of the problem.Thanx in advance. Melkman
htaccess and multiple htpasswd
No it won't ignore extra parts from your URL since you're using$(line end) in the regex here:^users/(\d+)*$Change your rules to:RewriteCond %{SCRIPT_FILENAME} !-d [OR] RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^ - [L] RewriteRule ^users/(\d+) profile.php?id=$1 [L] RewriteRule ^threads/(\d+) thread.php?id=$1 [L] RewriteRule ^search/(.*)$ search.php?query=$1 [L]
I have a question about htaccess and it's rewritings.I have this code:Options +FollowSymLinks RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^users/(\d+)*$ ./profile.php?id=$1 RewriteRule ^threads/(\d+)*$ ./thread.php?id=$1 RewriteRule ^search/(.*)$ ./search.php?query=$1whichexample.com/users/123is equals toexample.com/profile.php?id=123.if I change link to this:example.com/users/123/JohnWill htaccess ignore /John or any extra characters after the ID?the fact, John is the real-name of 123 ID, I want it to be.
ignore some part of the link using htaccess
In order to catch the query string, you need to use either%{QUERY_STRING}or%{THE_REQUEST}:Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / # Redirect /index?id=2 to /index/2 RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\?id=([^&\s]+) [NC] RewriteRule ^ /index?%1 [R=302,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [QSA,L]Given that you don't have other rules that may conflict with your needs, this should work just fine.Once you confirm its working you can change from302, to301but in order to avoid caching, tests should be always done using302.Another way using%{THE_REQUEST}would be like this:Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / # Redirect /index?id=2 to /index/2 RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+index\?id=([^&\s]+) [NC] RewriteRule ^ /index/%1? [R=302,L] # Internally forward /index/2 to /index.php?id=2 RewriteRule ^index/([0-9]+)/?$ /index.php?id=$1 [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [QSA,L]
I have a url likelocalhost/index?id=2How do I hide the id part by using htaccess and just show:localhost/index/2
hiding get variable in url
If you're trying to redirect pages to coresponding pages in subdirectory:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^([^/]+)/?$ /template/sr/$1 [L]
I have several pages inhttp://localhost/templatelike home.php, about.php, contact.phpInhttp://localhost/template/srI have the pages with the same name.This is what I have in my root .htaccess fileRewriteEngine on RedirectMatch 301 ^/$ http://localhost/template/sr/My error.log file reports:[localhost/sid#923dd8][rid#dd70b0/initial] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/ [localhost/sid#923dd8][rid#ddd0c8/subreq] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/index.php [localhost/sid#923dd8][rid#ddb0c0/initial] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/ [localhost/sid#923dd8][rid#ddd0c8/subreq] [perdir C:/xampp/htdocs/template/] pass through C:/xampp/htdocs/template/index.phpThis setup doesn't redirect I keep getting the pages from the root directory.
htaccess redirect all files in the root directory to coresponding pages in subdirectory
Given the list of address in your sample text these expressions will match the requested ranges by using alternation to match numeric ranges. Unfortunately they'll need to be constructed individually because of how a regular expression doesn't really evaluate the text. To match a182.52or182.53string you'd use a regex which contains the desired sub-strings and it would look like182.5[23].180.183.0.0/16 has a range 180.183.0.1 - 180.183.255.254^180\.183\.(?:[0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$180.210.216.0/22 has a range 180.183.0.1 - 180.183.3.254^180\.210\.[0-3]\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$180.214.192.0/19 has a range 180.183.0.1 - 180.183.31.254^180\.214\.(?:[0-9]|[12][0-9]|3[01])\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$182.52.0.0/15 has a range 182.52.0.1 - 182.53.255.254^182\.5[23]\.(?:[0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.(?:[1-9][0-9]?|1[0-9]{2}|2[0-4][0-9]|25[0-4])$
I have IP address list like this:180.183.0.0/16 180.210.216.0/22 180.214.192.0/19 182.52.0.0/15 ...(400 more)How can I make a regular expression for IP address with Subnetmask?Why I want to get this.I have a website with Load Balancer(I can't change any config in server), my client wants to deny access from specific country access. I use .htaccess like this.SetEnvIf X-Forwarded-For "59\.(5[6-9]|6[0-1])\.[0-9]+\." denyIP order allow,deny allow from all deny from env=denyIP
How can I make a regular expression for IP address with Subnetmask?
add folowing code to .htaccess file# cache images/pdf docs for 10 days <FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif)$"> Header set Cache-Control "max-age=864000, public, must-revalidate" Header unset Last-Modified </FilesMatch> # cache html/htm/xml/txt diles for 2 days <FilesMatch "\.(html|htm|xml|txt|xsl)$"> Header set Cache-Control "max-age=7200, must-revalidate" </FilesMatch>more informationhttp://tutorialpedia.org/tutorials/Apache+enable+file+caching+with+htaccess.html
I am working on one of the cakephp2 website speed improvement.now i need to setup some header expire and cache stuff.but in cakephp in which htaccess I have to put my code.And please suggest any nice htaccess codes.I have tried#Expire Header <FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$"> ExpiresDefault "access plus 2 hours" </FilesMatch>but its not working, also I have tried couple of other code but none of them working for me.Is there any key configuration that am missing?One more thing if is there any other tricks to improve performance then please suggest me.
how to add header expire in cakephp 2
To get mod_rewrite working not only mod_rewrite must be installed, but also check in the Apache directory config (/etc/apache2/sites-enabled/000-default on Ubuntu installed via apt-get) if the rule "AllowOverride None" exists in your project's directory config. If so, change it to "AllowOverride All".# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # **AllowOverride All**mod_rewrite can be installed by remove comment from this line#LoadModule rewrite_module modules/mod_rewrite.so
here i am stuck with a small problem. I have a site built in Yii framework. It runs without any problem with http protocol (the index.php in url is hidden and all urls work fine). I have hosted this in amazon ec2 services. i have the following lines in my .htaccess fileOptions +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.phpbut when i use https to browse the site (note: i have it all configured) , the home page loads normally. but the other urls does not work and requires /index.php/ to be added. what am i missing here?dying for answers.thanks in advance.
Hiding "index.php" at url in "YII" when using "https" does not work
Here's what we do:In config/database.php, we define a set of different DB settings, which are picked based on domain. You can adjust/extend that easily.if($_SERVER['SERVER_NAME'] == 'www.stagingserver.com'){ $active_group = "staging"; $db['staging']['hostname'] = "95.xxx.xxx.xxx"; } else { $active_group = "default"; } $db['default']['hostname'] = "localhost:8889"; $db['default']['username'] = "root"; $db['default']['password'] = "root"; $db['default']['database'] = "database"; $db['default']['dbdriver'] = "mysql"; $db['default']['dbprefix'] = ""; $db['default']['pconnect'] = TRUE; $db['default']['db_debug'] = TRUE; $db['default']['cache_on'] = FALSE; $db['default']['cachedir'] = ""; $db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_general_ci"; $db['staging']['username'] = "movers_user"; $db['staging']['password'] = "staging_user"; $db['staging']['database'] = "staging_database"; $db['staging']['dbdriver'] = "mysql"; $db['staging']['dbprefix'] = ""; $db['staging']['pconnect'] = TRUE; $db['staging']['db_debug'] = TRUE; $db['staging']['cache_on'] = FALSE; $db['staging']['cachedir'] = ""; $db['staging']['char_set'] = "utf8"; $db['staging']['dbcollat'] = "utf8_general_ci";
I am working on codeigniter site.I have one single application this application is used by various user each user is having its own DB(Its own clients also).I need the way how to approach this cloud system. As i have the single copy of application folder and only the difference in DB for each user. I have tried by creating subdomain directory in codeigniter and writing index file and htaccess file so that i can access my original application.but i need the subdomain path in url and way how to connect to the database according to that subdomian url path.htaccess file.RewriteEngine On RewriteRule /test/(.*) /$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.phpwhich way i should follow to complete this work.Please help Thanks in advance.
Setting database dynamically according to sub-domain URL in codeigniter?
For the mod_rewrite part:RewriteCond %{ENV:environment} != "dev" && != "local" RewriteCond %{HTTP_HOST} {DOESNT_CONTAIN .staging.com}would become:RewriteCond %{ENV:environment} !dev RewriteCond %{ENV:environment} !local RewriteCond %{HTTP_HOST} !\.staging\.comFor the mod_auth part, you'd need to set an env variable for the host and the dev/local:SetEnvIfNoCase Host .staging.com noauth=true SetEnvIf environment dev noauth=true SetEnvIf environment local noauth=trueThen add additionalAllowstatement:Allow from env=noauth
Morning,I've got 2 entries in my .htaccess file, and I want to make them a little more dynamic.Firstly I've got a non-www to www. redirect<IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>However, i'd like it to function conditionally as below<IfModule mod_rewrite.c> RewriteCond %{ENV:environment} != "dev" && != "local" RewriteCond %{HTTP_HOST} {DOESNT_CONTAIN .staging.com} RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [NC] RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>So basically, I want the www. redirect to kick in if the env variable doesnt equal dev or local, and the domain doesnt have .staging.com in itHow would I go about sorting this?Secondly, this is pretty much an identical issue, I've got some authenticationOrder deny,allow Deny from all AuthType Basic AuthUserFile /var/www/vhosts/{HTTP_HOST}/httpdocs/.htpasswd AuthName "Protected Area" require valid-user Allow from 127.0.0.1 Satisfy AnyI would like this to only run on the same conditions as above so: environment != "local" environment != "dev" url doesnt contain .staging.comHope some of you could shed some light onto this issue please.Many thanks!
.htaccess and environment variables (do X if Env isnt)
It is impossible to prevent the user from accessing those filesIn order to hear them they have to be downloaded to the user's computer and that means that they have to be accessible!The best you can do is encrypt the files and decrypt them in the player. But even then the player could be reverse-engineered and someone could discover the encryption key and algorithm. In the end you gonna find out that you just wasted a whole lot of processing time and in fact slowed down your application!
I have several audio files that I don't want to allow anyone else to gain access to them. Each file is in a separate folder inside a main folder, that I'll call "download" for now. So "download" has several other directories, and inside each directory are audio files. Those audio files are played with in a web app on the system.The problem is that right now anyone can type in the full address of the filelocalhost/download/dir/sound.wavand play the audio file. This is what I want to prevent from happening, I want those files to only stream when they are access or streamed from our application.I tried the following on the .htaccess filedeny from allThis just returned an403 forbiddenpage, but i was unable to stream the file from within the applicationRewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)localhost.com/.*$ [NC] RewriteRule \.(mp3|wav)$ - [F]This just disabled the stream all together did not return a 403 or anything it just did not stream from neither the application or direct accessFinally I'm using AJAX to call the script that holds the files to be streamed; are there any options I can use?
Prevent direct file access
Are you sure your Apache user (www-data?) can access the user file? Also, you can drop theAuthBasicProviderline.
httpd.confLoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_user_module modules/mod_authz_user.so LoadModule authz_core_module modules/mod_authz_core.so LoadModule access_compat_module modules/mod_access_compat.so LoadModule auth_basic_module modules/mod_auth_basic.so LoadModule auth_digest_module modules/mod_auth_digest.sohttpd-vhosts.conf<VirtualHost *:8080> ServerAdmin[email protected]DocumentRoot "/data/www/sites/default/public" ServerName 192.168.1.162 ErrorLog "/data/www/logs/apache/192.168.1.162-error_log" CustomLog "/data/www/logs/apache/192.168.1.162-access_log" combined <Directory "/data/www/sites/default/public"> Options -Indexes AllowOverride All Order allow,deny Allow from all AuthType Basic AuthName "Restricted Resource" AuthBasicProvider file AuthUserFile /data/svn/htpasswd Require valid-user </Directory> ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/sites/default/public/$1 </VirtualHost>I can get the info to input the user and password,but always can not be virified.I am sure the password is correct and the htpassswd file are not in the document root folder.How can i resolve this problem?
basic auth does not work in apache 2.4
Try using the.htaccessfile below:RewriteEngine On RewriteBase /xxx/CI/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L,QSA]Then, change youruri_protocolfromAUTOtoPATH_INFO:$config['uri_protocol'] = 'PATH_INFO';If that starts re-routing everything to the default controller, then change it toORIG_PATH_INFO:$config['uri_protocol'] = 'ORIG_PATH_INFO';Additional InformationInsert these lines into your file:Options -Multiviews +FollowSymLinks AllowOverride All
I want to remove the index.php file from file path in CI . I am using ubuntu 12.04 . I tried almost all the forum result but no sucess .I place the CI folder at this path .http://localhost/xxx/CI/I have apache rewrite mod enable .sudo a2enmod rewrite Module rewrite already enabledI also have this in my conf.php file$config['uri_protocol'] = 'AUTO'; $config['base_url'] = 'http://localhost/xxx/CI/'; $config['index_page'] = ''; $config['index_url'] = '';I have this in my .htaccess fileRewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L].htaccess file is at this pathhttp://localhost/xxx/CI/.htaccessand it is enable too through apache/etc/apache2/sites-available/default AllowOverride AllI get this error when i access the file like thishttp://localhost/xxx/CI/login/ 404 Error The requested URL /xxx/CI/login/ was not found on this server.Any help will be appreciated .Thanks
remove index.php file in CI ubuntu 12.04
You don't need 7000 separate rewrite rules, just useRewriteMap1 - First create a text file with all the 7000 chosen IDs in 2 columns like this:343 343 349 349 518 5182 - Then define a RewriteMap inhttpd.condlike this:RewriteMap idmap txt:/path/to/file/map.txt3 - And then enable mod_rewrite and .htaccess throughhttpd.confand then put this code in your.htaccessunderDOCUMENT_ROOTdirectory:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^threads/(.*)$ http://myotherdomain.com/threads/${idmap:$1} [L,NC,R=301]
How can I do a wildcard redirect in .htaccess file?I tried using the following, but the*doesn't work for some reason.redirect 301 /threads/*.343/ http://myotherdomain.com/threads/*.343/I can't use mod_rewrite, because I have 7000 of these redirects that I need to do, and apparently, when I tried about half of those, my server threw out a 500 misconfiguration error.So it seems that writing 7000 lines of the aforementioned code is somehow less intensive.Anyway, please let me know how I could express a wildcard in that sort of code.
Redirecting through .htaccess using a wildcard
If you want people to use/games/game-one/explicitly, you have to rewrite so that it requests/game/game-one.php. So the opposite way around than you have it in your question.RewriteEngine On RewriteRule ^games/game-one/$ /games/game-one.phpIf you want to rewrite other URL's too, then you'd need to use a technique similar to the prior answer.
I am only just starting to learn how to rewrite urls with the .htaccess file.How would I change:http://www.url.net/games/game_one.phpinto this:http://www.url.net/games/game-one/This is what I have been tryingRewriteRule ^/games/game-one.php ^/games/game-one/ [NC,L]
.htaccess basic mod rewrite
Per the comments below, the intent is to have user-visible URLs like /foo/bar/ that actually run php scripts like /foo/bar.php. In addition, you probably want users who try to load /foo/bar.php directly to be redirected to /foo/bar/ for consistency.#Redirect users loading /foo/bar.php to /foo/bar/ RewriteRule ^(.*)\.php$ $1/ [R] #Rewrite /foo/bar/ (what the user sees) silently to /foo/bar.php RewriteRule ^(.*)/$ $1.php [L]The[R]at the end of the first rule specifies to redirect rather than rewrite, so that the user loads /foo/bar/. The$1at the end of the second rule matches the parentheses (everything prior to the terminating slash) then tacks .php on the end. The[L]means to stop evaluatingRewriteRules.As in my original reply, the use of a leading slash for the replacement string depends on context. With these rules you'll be able to see the effect of the first rule since it's a redirect. If the redirect tries to go tomydomain.comfoo/bar/rather thanmydomain.com/foo/bar/, then add a leading slash before the$1in each rule.Another note - does your php script expect any query strings? There may need to be an additional tweak if it does.TheApache mod_rewrite referencehas more details.
I'm looking to set rules in my .htaccess file so that all files with a .php extension can be accessed by replacing the extension with just a slash (/foo/bar/would silently load/foo/bar.php). Previously, I foundthis, which is kind of what I'm looking for, except it only changes/foo/bar.phpto/foo/bar(notice there is no end slash).I'm almost a completely newbie when it comes to htaccess, and about 30 minutes of tweaking with the code from the previous link produced nothing by a ton of500 internal server errors. I'm sure it's such a simple fix, but neither Google nor trial and error have yet to bring me any results.Could anyone take a look at the code from the aforementioned post (copied below) and change it so that/foo/bar/will rewrite to/foo/bar.php?Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## hide .php extension # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L,NC] ## To internally redirect /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^ %{REQUEST_URI}.php [L]Many thanks!
.htaccess rewrite /foo/bar/ to /foo/bar.php
If your running apache, you may want to look intomod_rewriterules for your .htaccess file.In the following example, I redirect anything that is pointing to/users/user*to a file in the root of the site calledusers.php. You notice the([^/\.]+). This is a "catch-all" reg-ex that will allow me to create a variable for my query string (ex:?id=$1).<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^users/user([^/\.]+) users.php?id=$1 [L] </IfModule>Then in myusers.phpi can retrieve the variable as:$id = $_GET['id']This will allow me to catch and handle all user URLs with only 1 file.Note:This is only an example. It will have to be built upon but it could be a good starting point for you
How would I display dynamic content, say profile pages with the url syntaxmysite.com/users/user1mysite.com/users/user2mysite.com/users/user3Without having a different page or directory for every user. I'm hoping there is a way to just have something like an index.php file in the users directory and have it display appropriate user content based on the user1, user2, user3 part of the url.I know this is common but I'm not sure how to do it or what ever it would be called to google it?
Pages redirect (User friendly URL's)
It's not working maybe because the AllowOverwrite directive is not properly set : seethisYou should increase the log level withthisto see what happens.
Should I use an .htaccess file on a static HTML site? I want to hide .html extension from the url. Many of the code I've tried but none them are working.http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/How to hide .html extension from the website urlAnybody please help
Should I use an .htaccess file on a static HTML site?
Try\\p{Graph}+or\\p{Print}+@Test public void shouldMatch() { assertTrue("asdf123ASFD!@#$%^&*()".matches("\\p{Graph}+")); } @Test public void shouldMatchWithWhitespaces() { assertTrue("asdf 123 ASFD !@#$%^&*()".matches("[\\p{Graph}\\s]+")); }You can get more infos here (Section: POSIX character classes (US-ASCII only)):http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html
I want a regex which can match all numbers, letters, and all punctuation symbols as well (full stop, comma, question mark, exclamation mark, colon, etc.).The string must be at least one character long, but can be any length above that.Is it possible?
Regex to match all numbers, letters and punctuation symbols?
You need to make your application to generate the URLs like you want them, so in the form:example.com/fotograf/10/ example.com/fotograf/10/5/and following rewrite rule will make sure, it'll reach your php:RewriteEngine On RewriteRule ^fotograf/([0-9]+)/([0-9]+)/?$ fotograf.php?aid=$1&fid=$2 RewriteRule ^fotograf/([0-9]+)/?$ fotograf.php?aid=$1mod_rewritecan't rewrite URLs in your HTML pages...
I'm trying to rewrite urls for a page that has two query strings parameter. And according to these parameters value (set or not), I show different contents on the page.example.com/fotograf.php?aid=10 example.com/fotograf.php?aid=10&fid=5The URLs above are the examples to not rewrited ones. I just want to make them such thatexample.com/fotograf/10/ example.com/fotograf/10/5/The first URL links to the album with photos, and the second one links to a photo in that album.In.htaccess, I just want to be able to reach them with the clean URLs above. After that, I will check the URL at the top of the script and if it's not clean then with a function I wrote I will redirect it to clean one (by getting values with preg_match and preg_split and redirecting with header function).So far, I have tried this rule (which did not work to view album):RewriteRule ^fotograf/([0-9-/]+)/([0-9]+)/?$ fotograf.php?aid=$1&fid=$2 [L]Then, this (which redirects to album always):RewriteRule ^fotograf/([0-9-/]+)/?$ fotograf.php?aid=$1 [L]Finally, this (helped me to view the photo by a URL likeexample.com/fotograf/10/?fid=5):RewriteCond %{QUERY_STRING} ^fid=(.*)$ RewriteRule ^fotograf/(.*)/$ fotograf.php?aid=$1&fid=%1But I don't want to see any question marks or ampersands in the URL.Somehow, I need to check which one(s) is(are) set and redirect accordingly but I just don't know how to achieve this.How can I do this?Thanks in advance.
Handling Two Query Strings with .htaccess