Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
Use this rule:RewriteCond %{QUERY_STRING} ^task=view$ [NC]
RewriteRule ^(.*)$ $1? [R=301,L]?at the end of$1will strip-off any existing query string. | I'm not able to remove one GET parameter wrongly added by one 404 SEF module.I want to remove "task=view" only if it appears alone and not with another parameter.Sowww.mysite.com/1.html?task=viewshould be redirected towww.mysite.com/1.html.Whilewww.mysite.com?task=view&view=articleshould remain unchanged.No matter which RewriteRule I use, this paramater does not go. Looks like it is being generated from any environment variable when index.php is run.For example this does not work:RewriteCond %{QUERY_STRING} ^task=view$ [NC]
RewriteRule (.*)task=view.* $1 [R=301,L]Here is my .htaccess file:Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|.php|.html|.htm|.feed|.pdf|.raw|/[^.]*)$ [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
Options -IndexesWhat is the way to handle this? | Removing GET parameter in .htaccess |
You could leave theurl_suffixconfig blank$config['url_suffix'] = '';and define specific routes to add.htmlsuffix to some cases.For instance, for the blog posts:Inroutes.php(which is located atapplication/config/by default):$route['blog/(.+)\.html'] = "posts/view_post/$1";
/* ^ ^ ^
| | |
Controller --- Method --- Post SEO url or ID
*/ | I am using codeigniter 2.1.4 and I have set$config['url_suffix'] = ".html";It's working fine with out any trouble. But I found out that if I useredirect();function will always addurl_suffixon the landing page url. eg:site.com/login/success.html.My question is there anyway to exclude theurl_suffixwhile using theredirect()function? or is there anyway to add .html without settingurl_suffixin codeigniter, may be some hack in .htaccess??I tried to addRewriteEngine On
RewriteCond %{REQUEST_URI} !\.[a-zA-Z0-9]{3,4}
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1.htmlin the project htaccess file, but once i unset the url_suffix variable the framework throws 404 error. Any work around?Thanks :) | Restrict the url_suffix in codeigniter |
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.(co\.uk|com)
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]Or more generic:RewriteEngine On
RewriteCond %{HTTP_HOST} ^[0-9a-zA-Z-]+\.[a-zA-Z]{2,}$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] | my force www htaccess code is :RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]but i have problems withsubdomainsex:abcdef.example.com ====> www.abcdef.example.comand i want to edit code to be worked like these:example.com ===> www.example.com
abcdefg.example.com ===> abcdefg.example.com
example.co.uk ===> www.example.co.uk
abcd.example.co.uk ===> abcd.example.co.uk | force www in htaccess except all subdomains |
I figured it out through a bunch of trial and error:RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/sub
RewriteRule ^(.*)$ sub/$1 [L] | so my subdomain currently goes to the same root folder as my domain. I would like to accomplish the following:sub.domain.com => sub.domain.com/sub/with the /sub/ portion invisible to the user.I do not want to have the following happen:sub.domain.com => domain.com/sub/Is there any way I can accomplish this without redirection and without getting stuck in an endless loop? I have this currently and I don't think it's working as it doesn't mask the /sub part:RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/sub
RewriteRule .* http://sub.domain.com/sub[L]I've looked endlessly online for something that accomplishes this but can't seem to find it... | Hide subfolder for subdomain |
You can't use a relative location for the-ftest. You'll need to include the full path:RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/folder/offline.txt -f
RewriteCond %{REQUEST_URI} !/websiteOffline.php
RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78$
RewriteRule ^(.*) /websiteOffline.php [L]where/folder/is the path that your htaccess file is in.Here, if your IP address is12.34.56.78and you try accessing the folder, it won't redirect you. | I want to use htaccess to check if a file called offline.txt exists in the same directory as the htaccess file, if it exists then do:RewriteRule ^.*$ /websiteOffline.php [L]and also have an exception to a certain range of ip addressesThe idea is that if i want to take my entire site down for maintanance i could simply place a file called offline.txt and that would do it and allow certain ip's to bypass this condition.Any suggestions on how this can be acheived?Thanksi've tried the following code but doesnt seem to work:RewriteEngine on
RewriteCond /offline.txt -f
RewriteRule ^(.*) /websiteOffline.php [L]updateJust used Jon's suggestion as folows:RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/offline.txt -f
RewriteRule ^(.*) /websiteOffline.php [L]Slight problem with this is that the file websiteOffline.php is in the folder where the rewritecond is applied so hence is not able to display that file. any suggestions | RewriteRule htaccess if a file exists |
Change order of your rules:<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>In general keep your 301 rules before your internal rewrite rules. | I have a Laravel 4 installation, and I used the boilerplate's htaccess to redirect my site from:site.com.brtowww.site.com.br(notice thewww).But when I use a route such assite.com.br/TITLE-OF-MY-POSTI am redirected to:www.site.com.br/index.phpinstead ofwww.site.com.br/TITLE-OF-MY-POST"Does anyone know why? Here my htaccess rules:Laravel's rule<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>Boilerplate's rule<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule> | Htaccess redirect Laravel 4 |
Your# Add trailing slashrule appears to be problem. Can you try commenting it out for testing./app/.htaccessOptions +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /app/
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s/+(.+?[^/])[?\s] [NC]
RewriteRule ^ /%1/ [L,R=301]
# remove /public/ from URL
RewriteCond %{REQUEST_URI} !/public/ [NC]
RewriteRule ^(.*?)/?$ public/$1 [L] | QuestionHow can I remove/public/from my URLs?ProblemWhen I go to visit/app/aboutthe URL changes to/app/public/aboutandapp/user/2changes to/app/user.php/?username=2Setup/app/ .htaccessThe.htaccessoutside of thepublicfolder contains:Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /app/
# remove /public/ from URL
RewriteCond %{REQUEST_URI} !/public [NC]
RewriteRule ^(.*)/?$ public/$1This works fine. When I visitlocalhost:8888/app/it loads up theindex.phpfile inside thepublicfolder./app/public/ .htaccessThe.htaccessinside of thepublicfolder contains:Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# Add trailing slash
RewriteCond %{REQUEST_URI} ^(.+[^/])$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . %1/ [L,R=301]
# API Pages
# ------------------------------------------------------------
RewriteRule ^user/([a-z0-9]+)/?$ user.php?username=$1 [L,NC]
# Generic Pages
# ------------------------------------------------------------
RewriteRule ^about/?$ about.php [L,NC]
# Error Pages
# ------------------------------------------------------------
ErrorDocument 404 /404.phpRelated:URL-rewriting with index in a "public" folder | .htaccess: remove public from URL |
Well there is little bit of security issue with.htaccessin the sense that if a hacker/intruder gets hold of your file system then they can modify rewrite rules and change the behavior of your website. However do remember that if a hacker gets hold of your DOCUMENT_ROOT folder then a lot more damage can be done by modifying/deleting any other code as well and you have much bigger problem in your hand.However what.htaccessprovides you is utmost flexibility by letting you control your website behavior, authentication needswithout need to make those changes in Apache config and restart it every time.Especially in a shared hosting environments Apache config is not even accessible for website owners. | There are all sorts of posts out there that advise you on how to add a .htaccess file to remove index.php from the URL. However, in order to get .htaccess files to work, the AllowOverride must be changed (usually to "All").This tutorialexplains that using .htaccess files for mod_rewrite is a misconception and can and should be done in the main config file.I have been informed by my web security officer that - and I quote - "to change AllowOverride to All increases the risk to the web server as, if exploited, an intruder / hacker / opportunist could override the main servers configuration, which could allow them to get up to allsorts; this would be a serious security breach". I'm not sure how much weight this holds!So my question is;are there really serious dangers to changing the AllowOverrideand if so, why is .htaccess being recommended for removing index.php so widely onStack Overflow? | AllowOverride security issues |
These rules should work for you:RewriteEngine On
## Adding a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !/$
RewriteRule . %{REQUEST_URI}/ [L,R=301]
## hide .php extension
# To externally redirect /dir/file.php to /dir/file
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1/ [R=301,L,NE]
# To internally forward /dir/file/ to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L] | I also want to 301 redirect any url that ends in.php. Then I internally redirect anything that ends in a/to the name before/plus.php. These both work fine when they are alone. But putting them in the same.htaccessI get aThe page isn't redirecting properly.What am I doing wrong here?RewriteRule ^(.*)\.php$ /$1/ [R=301,L]
RewriteRule ^(.*)/$ $1.php [QSA,L] | htaccess rewrite if url extention is .php remove it |
+100Since, the environment%{env}variables are not behaving consistently across different Apache versions, I suggest setting thecookiewith aRewriteRuleitself using the[CO]cookieflag.RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteCond %{HTTP_COOKIE} visitor_id=([^;]+) [NC]
RewriteRule .* $0/vid/%1 [C] # Appends the cookie value to the URL
RewriteRule ^(.*)/vid/(.*)$ http://example.com/$1 [L,R=301,CO=visitor_id:$2:.example.com:14400:/]Here are the list of changes made to your.htaccessfile:RewriteCondmatches are case-insensitive now (using[NC])The dots in%{HTTP_HOST}condition have been escaped\.(.matches any char otherwise)The firstRewriteRuleappends the visitor id (captured as%1) to the URL (captured as$0)The lastRewriteRuleparses the visitor id from the URL (as$1) and performs a permanent[R=301]redirect tohttp://example.comalong with writing a cookie namedvisitor_idusing the[CO]flag.The syntax of thecookierewrite flag is as follows[CO=NAME:VALUE:DOMAIN:lifetime:path:secure:httponly]where specifying values forname,valueanddomainis mandatory. Thelifetimedefaults to0which means the cookie persists for the current browser session only.Pathdefaults to/,secureandhttponlytofalse.The[CO]flag used specifiesdomainas.example.comso that thecookiebecomes accessible to all the hosts underexample.comdomain. Thelifetimeis specified as14400which is in minutes and so amounts to10days. | .htacces redirects fromwww.example.comtoexample.com(same domain without www.)Returning visitor could have in user-agent avisitor_idcookie.I want to bring this value through domains within a cookie or session.I tried this, but the cookie is created for the www domainRewriteCond %{HTTP_HOST} ^www.example.com
RewriteCond %{HTTP_COOKIE} visitor_id=([^;]+)
RewriteRule .* - [C,env=foo:%1]
RewriteRule ^(.*) http://example.com [L,R=301]
Header set Set-Cookie "visitor_id=%{foo}e; path=/" env=fooMoreover the environment variable works on localhost (Apache 2.4.2, Win32), but online (Apache 2.2.25, linux) the value in cookie is"%{foo}e"instead of expected number.Also tried withmod_session_cookiebut can't find practical examples.How redirect through domains, bringingvisitor_idin a cookie or session cookie? | htaccess from www to non-www bringing variable in session/cookie |
Add extra conditions to your redirect rule:RewriteCond %{REQUEST_URI} !/this-page\.html
RewriteCond %{REQUEST_URI} !/this-page2\.html
RewriteCond %{HTTP_HOST} ^www\.additional-domain\.com [NC]
RewriteRule (.*) http://www.main-domain.com$1 [R=301,L] | I currently have a website on one domain and it has another domain mapped to it. I have a .htaccess RewriteCond like the following:RewriteCond %{HTTP_HOST} ^www\.additional-domain\.com [NC]
RewriteRule (.*) http://www.main-domain.com$1 [R=301,L]This obviously means that any pages accessed by going to www.additional-domain.com will redirect to the correct page on www.main-domain.com.What I would like to know is; can I keep this rule but have certain pagesnotredirect? so for page /this-page.html if the user accessed www.additional-domain.com/this-page.html then they arenotredirected to www.main-domain.co.uk/this-page.htmlIs this even possible? Thanks.-------- EDIT --------I neglected to mention that for those additional pages I want the redirect to work in reverse.So if someone accessed www.main-domain.co.uk/this-page.html then they would be redirected to www.additional-domain.co.uk/this-page.html | .htaccess RewriteCond for a specific page |
Try thisRewriteEngine on
RewriteCond %{REQUEST_URI} !index.php
## if the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?test=$1 [NC,L] | I have a problem, URL's have been rewritten like thisRewriteEngine on
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.*)$ index.php?test=$1 [NC,L]None of my images, nor css styles are being applied. I have tried<base href="/">, but it is not working.Any solutions? | .htaccess images not showing after rewriting |
I know, this is an old question as well as the fact, that the problem is somewhere else. Though, this could be something you can maybe use for other things.
The RewriteEngine knows variables, so you could use conditions or just add the%{TIME}to the callRewriteCond %{TIME_SEC} <30
RewriteRule .* /first.html [L]
RewriteCond %{TIME_SEC} >29
RewriteRule .* /second.html [L]You could also play around with the other variables. | Currently I'm adding aRandom Numberto the end of myAjaxURLs via Javascript or PHP. I'm wondering if I could do the same just inside of my.htaccessfile, when I'm rewriting them using mod_rewrite.Is there any way to making aRandom NumberorStringin a.htaccessfile on-the-fly?Edit:I don't have any problem in my current code. I just want to know if I could generate a random number in the .htaccess file or not. I've already searched the 'net, but couldn't find anything helpful yet.Update:Well, I just realized thatAjaxrequests caches on theClient-side, but the.htaccessworks on theServer-side. So, my question seems totally useless now (at least in my own case), but thanks for sharing your ideas. | Generating random numbers directly inside a .htaccess file |
RewriteEngine On
RewriteBase /
RewriteRule ^page$ /subfolder/subfolder/thepage.php [L] | I have a php page:www.mydomain.com/subfolder/subfolder/thepage.phpI want to access it via:www.mydomain.com/pageHow is that possible using the .htaccess file?!I want to use an alias or virtual name to replace the long directory url. | htaccess redirect virtual alias to url |
You cannot do it like in your example as you are rewriting everything:^(.*)$.If you want two different rules, you would need to select what urls you want to write to what end destination.An example where you rewrite different urls that start with different strings to different destinations:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^starts_with_this(.*)$ profil.php?upime=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^starts_with_something_else(.*)$ novica.php?nid=$1 | I have this rule:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profil.php?upime=$1and it is working. Now I want to know how to rewrite the URL of another page:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ profil.php?upime=$1
RewriteRule ^(.*)$ novica.php?nid=$2 - I did this, but is not working.what can I do that I will have both rules in one.htaccessfile? | .htaccess multi URL rewriting |
Try removing the(.+)part from your regular expression. It makes it so youneedsomething after thebrochure.pdf. Also add some boundaries:RewriteEngine On
Options +FollowSymLinks
RewriteRule ^/?eventdays-2012/brochure.pdf$ /sites/default/files/docs/fact_sheet-204499207.pdf [L] | I would like to create a friendly url for a specific file from a directory that has a long file path as well as renaming the file. I am not even sure if this is possible.So far I have tried in htaccess:RewriteEngine On
Options +FollowSymLinks
RewriteRule eventdays-2012/brochure.pdf(.+)$ sites/default/files/docs/fact_sheet-204499207.pdf... but this is not working.I've done some searching and see where you can mask an entire directory in the file path but in my case I just want to do one file within the directory, create a directory name and change the file name as well. | Rewriting path for a specific file using htaccess |
I got solution which worked for me.RewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/]+)/([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L,QSA]Thanks everyone :) | Sorry I changed the previous question. I have problem with .htaccess rewrite rule on localhost, I have .htaccess file in http:// localhost/testing/.htaccess.
I want to change url like belowhttp://localhost/testing/site.php?site=testtohttp://localhost/testing/testAnd I have code in .htaccess asRewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]Which is working correct, but I have also url likehttp://localhost/testing/pages.php?site=test&pid=2Here pages.php with two parameters as site name and page id. I want rewrite this ashttp://localhost/testing/test/2For both conditions I have bellow code which is not workingRewriteEngine on
RewriteRule ^([^/\.]+)/?$ site.php?site=$1 [L]
RewriteRule ^([^/\.]+)/?$ pages.php?site=$1&pid=$2 [L]Please HelpThanks :) | htaccess rule is not working on localhost |
You need to match against the%{THE_REQUEST}to ensure that you're matching against the actual request and not an internally rewritten URI:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /categoryname/page/([0-9]+)
RewriteRule ^ /categoryname/%1 [L,R=301]
RewriteRule ^/categoryname/([0-9]+)$ /categoryname/page/$1 [L]These have to be before the wordpress rules. | I have problem with changing pagination URL in Wordpress. I know that universal solution for this is to changing Wordpress core files, but I need this solution only for one category. Maybe for only one category this can be done by htaccess?There is now URL like this:http://mysite.com/categoryname/page/3and I want change it to this:http://mysite.com/categoryname/3Thanks for any response | Remove "page" from pagination URL |
Since the sites are served by a load balancer, it turns out that the redirect to https logic was actually being implemented at the load balancer level. | I am working on a site that, when accessed viahttp, gets auto redirected tohttps. We're trying to determine where this is occurring. So far we've looked in the following places:.htaccessin apache in thehttpd.confin the php file of a test page we wrote (site.com/test.php)I'm thinking there could be some otherconffile in apache that this redirect stuff would be occurring..where else should I look? | How to determine where a redirect to https is occurring |
From fossil help for the 'addremove' command:Files and directories whose names begin with "." are ignored unless the --dotfiles option is used. | I have a website with many .htaccess files in it. But fossil does not save them in repo when I use addremove. Instead, I have to add each htaccess file by hand (using the add command). What is happening?Fossil 1.22 (2012-03-17 17:53:25), Win32. | FOSSIL (version control system) does not add .htaccess files. Why? |
Don't know if you still have this issue, but I have had it on one of my domains (Yourls installation). Try:RewriteEngine On
RewriteRule ^$ http://www.example.com/ [R=301,L]It works on my installation, but check it out on your site. | I'm looking to redirect my domain example.com and www.example.com tohttp://example2.com, but I want to keep all visits to my posts athttp://example.com/sdfhsto continue through to their destinations.Essentially, I ONLY want to redirect the root and www domain and leave the rest untouched.How can I do this with .htaccess? | Redirect root (and only root) URL to another domain? |
The first line enables Includes also known as SSI (server-side includes) for the two mime types:application/javascriptandapplication/jsonThe second lineSetOutputFilter INCLUDESprocesses the files for includes before outputing them but only for the files contained in the regex path"\.combined\.js$"and basically does what the first is doing but it's a backup.Your missing a crucialOptionflag. And that'sOptions +Includesto enable includes to begin with. That may be why it is not working on the other serverI hope your not including that space after the<and it was a typo because surely that will not work on any version of apache if I'm not mistaken. It should be without spaces as follows:<!--#include file="libs/jquery-1.5.0.min.js" -->
<!--#include file="plugins/jquery.idletimer.js" -->You will also need to enablemod_includemodule in your Apache httpd.conf.http://httpd.apache.org/docs/2.2/mod/mod_include.htmlLoadModule include_module modules/mod_include.soI'm pretty sure you got this code from the HTML5-Boilerplate .htaccesshttps://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess#L887-L917 | I found the following htacess that allows concatenation from within specific js files<FilesMatch "\.combined\.js$">
Options +Includes
AddOutputFilterByType INCLUDES application/javascript application/json
SetOutputFilter INCLUDES
</FilesMatch>e.g. Inside of script.combined.js you could have< !--#include file="libs/jquery-1.5.0.min.js" -->
< !--#include file="plugins/jquery.idletimer.js" -->and they would be included into this single file.I want to know how do these two line - line 2 n 3 of the .htaccess combine files.Also these have worked on several systems but on my ubuntu 12.04 with Apache 2.2.22 they don't work. why? | .htaccess to combine files |
To do the job and allow from IP without password prompt, and also allow from any address with password prompt, it work perfect like this :Order deny,allow
Deny from all
AuthName "password please"
AuthUserFile /home/accountpath/.htpasswd
AuthType Basic
Require valid-user
Allow from 192.168.1.1
Satisfy Any | Using the following.htaccess, I am able to successfully limit access to users with the correct username/password and users from a specific IP address:AuthType Basic
AuthName "Please enter your password"
AuthUserFile /path/to/.htpasswd
Require valid-user
Order deny,allow
Deny from all
Allow from 123.123.123.123
Satisfy AnyThis works on a number of different servers, however, today I came across a server where thisdoesn'twork 100%. Users with the correct username/passwordcanlogin, but users from the specified IPare notallowed and are forced to enter a password.Is there something inhttpd.confthat might be preventing the IP whitelist from working? I've tried a number of variations and continue to get the same result. All servers are Apache on Linux. | Whitelisting IPs with .htaccess / .htpasswd |
Make that something like:RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !yourdomain\.com [NC]
RewriteCond %{HTTP_REFERER} !alloweddomain\.com [NC]
RewriteRule .? - [F]The firstRewriteCondchecks that the referrer is not empty. The second checks that it doesn't contain the stringyourdomain.com, and the third that it doesn't contain the stringalloweddomain.com. If all of these checks pass, theRewriteRuletriggers and denies the request.(Allowing empty referrers is generally a good idea, since browsers can generate them for various reasons, such as when:the user has bookmarked the link,the user entered the link manually into the address bar,the user reloaded the page,the browser is configured not to send cross-site referrer infromation, ora proxy between your site and the browser strips away the referrer information.) | Is it possible to accept traffic from only one domain, ideally using a .htaccess file?
I want my site to only be accessible via a link on another site I have.I know how to block one referring domain, but not all domainsRewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} otherdomain\.com [NC]
RewriteRule .* - [F]this is my full rewrite code:RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !domain\.co.uk [NC]
RewriteRule .? - [F]
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]I think it is working, but none of the assets are getting loaded and I get a 500 error when I click on another link. | Deny referrals from all domains except one |
Usually it is safe to includeRewriteCond %{REQUEST_URI} !-fin Rewrite rules so that physical files like css, js, images etc are not affected by these rules.However in your casenone of your rules will impact these css, js, images filesbecause you are not including dot character.in your matching reular expression.To overcome your issue I recommendusing absolute path in your css, js, images filesrather than a relative one. Which means you have to make sure path of these files start either withhttp://or a slash/. | i have a question regarding .htaccess file access for css files and js filesi have this:RewriteEngine On
RewriteBase /
RewriteRule ^$ index.php?page=index [L,NC]
RewriteRule ^([a-z0-9]+)/?$ index.php?page=$1 [L,NC]
RewriteRule ^([a-z0-9]+)/([a-z0-9]+)/?$ index.php?page=$1&subpage=$2 [L,NC]now, i realize some files (like js, css) load correctly without using:RewriteCond %{REQUEST_URI} !-fwill it be better if I add it before my rules, or it doesnt matter? | .htaccess file access |
+50This is your corrected/updated .htaccess, however it would have been better if had written more about your actual requirements:Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#open the product details page with the Product Number with PN prefix
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((products/|product/|)PN[0-9-]+)/?$ product.php?pno=$1 [L,NC,QSA]
#open the product search page for a particular category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((bat|ref|acc)[A-Za-z0-9-]+)/?$ search.php?cat=$1 [L,NC,QSA]
#open the product search page for a particular category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-_.,]+)/?$ search.php?search=$1 [L,NC,QSA]
RewriteRule !\.(html|php)$ - [S=4,NC]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
RewriteCond %{ENV:uscor} ^Yes$About your css, js, image file: Make sure your path to css, js etc start with a slash/and not a relative one. | I’ve written .htaccess file as follows:Options +FollowSymLinks
RewriteEngine On
#open the product details page with the Product Number with PN prefix
RewriteRule ^((products/|product/|)PN[0-9-]+)/?$ product.php?pno=$1
#open the product search page for a particular category
RewriteRule ^((bat|ref|acc)[A-Za-z0-9-]+)/?$ search.php?cat=$1 [NC]
#open the product search page for a particular category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-_.,]+)/?$ search.php?search =$1 [NC]
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
RewriteCond %{ENV:uscor} ^Yes$It couldn't accept if there is dot(.) in the query string value. Now, it is solved, but can't accept its previous rule.Furthermore, I want it to rewrite the "URL/product.php?pno=PN123" properly if the URL "URL/products/PN123" or "URL/product/PN123" is given. Please note that it can redirect correctly if "URL/PN123" is given correctly with proper CSS. AND "URL/product/PN123" can also retrieve the data but can't show CSS prperly. | htaccess: generates error if dot(.) exists in query string |
Not sure what the problem you're having is exactly, but if I change your rules to this, it works for me:ErrorDocument 404 /index.php
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]So instead of checking if the request isn't accessing an actual file/directory that exists, check that the .php version of that file DOES exist. | I'm using the below in myhtaccessfile to strip out the.phpextensions on my files. It works fine.However, I also want to utilizeErrorDocument 404 /index.phpto redirect any non existing urls back to the homepage. If I useErrorDocument 404 /index.phpalone in thehtaccess, the redirects work fine. Also, if I use the below Rewrite code it successfully strips the php extensions. I would like both of these to work together, however.For example, if a user enters "www.domain.com/register", they go towww.domain.com/register.php. But if they enter "www.domain.com/something", andsomething.phpdoesn't exist, then they redirect back toindex.php. I've tried every permutation of both of these together in myhtaccessto no avail. Any help would be appreciated.Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L] | htaccess ErrorDocument 404 conflict with RewriteEngine On |
Try the following to prevent the looping#prevent internal redirects, and prevent loop
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteCond %{REQUEST_URI} /index.php$
RewriteCond %{QUERY_STRING} ^page=foo$
RewriteRule ^.*$ http://www.domain.com/my-pretty-url/? [R=301,L]
RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L] | I'm attempting the following in an HTACCESS file:I want to 301 redirect this -->http://www.domain.com/somepage.php?page=footo this -->http://www.domain.com/my-pretty-url/This works fine when I alter internal links on the site to read how I want and I DO NOT use the R=301 flag:RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L]BUT... the hitch here is I also want to 301 Redirect any external requests to the server, which when I handle that it puts me in a redirect loop.RewriteCond %{REQUEST_URI} /index.php$
RewriteCond %{QUERY_STRING} ^page=foo$
RewriteRule ^.*$ http://www.domain.com/my-pretty-url/? [R=301,L]
RewriteRule ^my-pretty-url/$ /index\.php?page=foo [L]The RewriteCond rules don't work by themselves, only the single RewriteRule at the bottom works by itself for internal rewrites, but it doesn't handle outside requests.Obviously, if I have both together, it's creating a loop. How do I get around this??Thanks! | .htaccess redirect loop when Redirect and RewriteRule together |
Try this:Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^products/price-lists/([a-z0-9_\-]+)(/page)?/?$ products/price-lists/$1.php?page=1 [NC,L]
RewriteRule ^products/price-lists/([a-z0-9_\-]+)/page/([0-9]+)/?$ products/price-lists/$1.php?page=$2 [NC,L]The first rule will check if a page is there or not without a number and go to page 1. The([a-z0-9_\-]+)will be use to put the company, so if you put:http://www.domain.com/products/price-lists/stackoverflow/page/2the/products/price-lists/stackoverflow.phpwill open using$_GET['page'] = 2 | I have a series of price lists from various manufacturers (spat out from a database). They are limited to 100 rows per page, ie:www.domain.com/products/price-lists/company1.php?page=2
www.domain.com/products/price-lists/company2.php?page=10which i want to rewrite to:www.domain.com/products/price-lists/company1/page/2
www.domain.com/products/price-lists/company2/page/10I have:Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^products/price-lists/company1/page/([0-9]+)/?$ products/price-lists/company1.php?page=$1 [NC,L]
RewriteRule ^products/price-lists/company2/page/([0-9]+)/?$ products/price-lists/company2.php?page=$1 [NC,L]First of all, this throws a 404 if i try to go to /products/price-lists/company1/page/2 (it works if i remove /page/) and second, i was wondering if i could combine them into one rule anyway:(company1|company2[0-9]+)/?Thanks for any help (this is my first mod_rewrite attempt!) | How to rewrite numerous URL's at once? |
Add the following to your .htaccess file in the root of your domain.com site.RewriteEngine On
RewriteBase /
#if request is not on www.domain.com
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
#and it is not for a folder starting with /bbb/
RewriteCond %{REQUEST_URI} !^/bbb/ [NC]
#redirect to www.domain.com/bbb/
RewriteRule .* http://www.domain.com/bbb/ [L,R=301] | I have a multisite with drupal, I created a site which at first should be accessible in multiple ways (subdomains and paths), but now I want keep just one of them; so I whould redirect all the others. Right now I have:aaa.domain.com/bbb.domain.com/domain.com/aaa/domain.com/bbb/www.domain.com/aaa/www.domain.com/bbb/And I want to redirect all of them tohttp://www.domain.com/bbb/I tried to write:RewriteCond %{HTTP_HOST} ^aaa.domain.com$ [OR]<BR>
RewriteCond %{HTTP_HOST} ^bbb.domain.com$ [OR]<BR>
RewriteCond %{HTTP_HOST} ^www.domain.com\/aaa$ [OR]<BR>
RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/bbb\/" [R=302,L]I will use 302 and no 301 until it work as expected.If I entern aaa.domain.com it works as expected, but if I enterhttp://aaa.domain.com/page/1it don't workI have read anything I can about htaccess, but I am missing something.Thanks | htaccess redirect subdomain to subdirectory |
I would replace spaces with dashes in PHP and then redirect to the new version of the URL to get easily readable addresses. (Space is encoded as %20 which is not exactly easily readable)That way you would still be able to enter the addressdomain.com/new york citybut would be redirected todomain.com/new-york-cityinstead ofdomain.com/new%20york%20city.The replace in .htaccess is possible with something like this:RewriteRule ^([^\s]*)\s(.*) $1-$2 [N](Based on answer toSearch and replace in apache htaccess a RewriteRule) | I'm trying to trim down my urls using htaccess having my index.php act as the key with the following code:RewriteEngine on
RewriteRule ^([^/]+)$ index.php?city=$1 [NC]To use this with my members area, do i just add the following to work on mysite.com/members/index.php?city=$1RewriteRule ^members/([^/]+)$ index.php?city=$1 [NC]in the event of a city having multiple words, ie: new york city, whats the best way to approach this? defining it in the .htaccess (not sure if thats possible) to change new york city -> new-york-city or actually any space to a dash. Or, do it in php with a function to replace ' ' -> '-' for the db queries that use $_GET? | htaccess redirect using mod_rewrite for seo friendly urls |
Update your .htaccess with this code:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^my\-short\-list/([0-9]{1}[a-z0-9]{7})/?$ /my-short-list/?u=$1 [NC,L]
RewriteRule ^user\-reviews/([0-9]+)/?$ /user-reviews/?urid=$1 [NC,L]
RewriteRule ^videos/([0-9]+)/([0-9]+)/([a-z0-9\-]+) /videos/?vid=$1&pid=$2&url=$3 [NC,L]
#wp default
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule> | I've been trying to to find a solution using .htaccess to redirect the following urls:from:mydomain.com/my-short-list/1AXC7682 or mydomain.com/my-short-list/1AXC7682/to:mydomain.com/my-short-list/?u=1AXC7682from:mydomain.com/user-reviews/42 or mydomain.com/user-reviews/42/to:mydomain.com/user-reviews/?urid=42and finally:from:mydomain.com/videos/1055687406001/130433/bmw-i8-concept-sports-car-in-detail or
mydomain.com/videos/1055687406001/130433/bmw-i8-concept-sports-car-in-detail/to:mydomain.com/videos/?vid=1055687406001&pid=130433&url=bmw-i8-concept-sports-car-in-detailThank you! | htaccess redirection |
It should be possible using the SetEnv directive. Try putting this in your .htaccess:SetEnv PERL5LIB /home/username/perlIf you want to add more than one path, separate them with:, like this:SetEnv PERL5LIB /home/username/perl:/some/other/pathYou can (of course) also use this to set other environment variables.Another option would be adding it to the include path from inside Perl itself. You will have to add the lineuse lib "/home/username/perl";to the CGI script(s), somewhere before it loads the module(s) installed there. | I've used Cpanel to install per modules on my host server running lightspeed.
It gave an "Installation Successful" message too.But it shows:Location of Your Perl Module(s)Path: /home/username/perlUsing Your Perl Module(s):You will need to add /home/username/perl to the include path.Is it possible to add it using only .htaccess? Because it's my only access to the server. | add Perl Modules' Directory to include path using .htaccess for CGI scripts |
http://www.nfrases.com/tag.php?id_tag=10&id_frase=508becomeshttp://www.nfrases.com/10/508with this in your .htaccessOptions +FollowSymlinks -MultiViews
RewriteEngine On
RewriteRule ^([0-9]*)/(.*)/?$ /tag.php?id_tag=$1&id_frase=$2 [L,QSA]Untested. Let me know if it works for you. | I have this addresshttp://www.nfrases.com/tag.php?id_tag=10&id_frase=508that I would like to make it a lot shorter and more SEO friendly to something like (I don't know ... open to suggestions)http://www.nfrases.com/tag/10/508orhttp://www.tag10name.nfrases.com/508I need help with how to code this, because a simple thing as trying to make the address alwayshttp://www.nfrases.comcase the user goes tohttp://nfrases.comorwww.nfrases.comI tried and failed :(Used this code by the way:Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301] | htaccess mod_rewrite Shorten to a SEO friendly URL |
I don't really know what you mean bywhich is forwarded to www.mainme.comIf it get's forwarded with a HTTP-redirect you need to change that redirect to your needs (so attach/cookieor/puppyat the end).If your domains are sharing the same documentroot you need to place this code in your .htacces in it:RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?cookie\.com$
RewriteRule ^(.*)$ http://www.mainme.com/cookie? [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?puppy\.com$
RewriteRule ^(.*)$ http://www.mainme.com/puppy? [R,L]EDIT:So you might have the http-referer as clue where the user came from. Try this:RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http[s]?://(www\.)?cookie\.com(.*)?$
RewriteRule ^(.*)$ http[s]?://www.mainme.com/cookie? [R,L]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?puppy\.com(.*)?$
RewriteRule ^(.*)$ http://www.mainme.com/puppy? [R,L] | I want to redirect several domains to different sub directories. For example:If a visitor uses the domain www.cookie.com which has a HTTP redirect to www.mainme.com then when the visitor gets there, Apache detects the domain and redirects it to mainme.com/cookieSame for puppy.com. If it gets HTTP redirected to mainme.com, when the user gets there it gets redirected to mainme.com/puppyCan this be done in .htaccess?Using Linux as server with /var/www as web folder.Not using Virtualhost right now but learning how to do it. | How to redirect multiple domains to different sub directories with Apache |
Try something like this:<VirtualHost 1.2.3.4:80>
DocumentRoot /var/www/mydomain.com
ServerName mydomain.org
ServerAlias mydomain.net mydomain.info mydomain.me
RedirectPermanent / http://www.mydomain.com/
</VirtualHost> | I have an Ubuntu Server that runs Apache w/ Virtual Hosts. I run a website with the primary domain as "mydomain.com" and it's located in /var/www/mydomain.com.Assuming I own multiple domain names (each with a different tld), what's the best way to make sure they all point to "mydomain.com" (the primary site).In other words, is it best to create an .htaccess file in /var/www that has multiple 301 redirects for sites like "mydomain.net" and "mydomain.org" that point to "mydomain.com"? | Multiple TLD's - .htaccess 301 Redirect |
You could useRewriteMapwith the external program mapping (prg:). This is a quite adavnced use of mod-rewrite and even of RewriteMap.RewriteLock /var/lock/rewritemaplock.lock
RewriteMap base16to10 prg:/somewher/modrewritemapbase16to10.pl
RewriteRule - ${base16to10:%{REQUEST_URI}}And for the perl script (or any other language), not tested#!/usr/bin/perl
$| = 1; # Turn off I/O buffering
while ($uri=<STDIN>) {
sprintf("/someResourse/id/%d",hex($uri));
}You may need to test and extend the program, at least you need to return the "NULL" string in case of error. You may need also to add someRewriteCondbefore calling this rewriteRule if some other url shouldn't be converted.You can use other languages for the base 16 to 10 rewriter,here's an example in PHP. | I intend to do a url redirection of the form :from:domain.com/Aintodomain.com/someResourse/id/10in this redirection the base of the id is changed from16to10.I wonder if this is possible using .htaccess | number base conversion in .htaccess |
There are multiple ways to solve this problem, but here's one that always suits my needs.Guide all your URL requests through the index.php first and resolve the request in your PHP code second.1) Use an .htaccess file to direct all URL's through index.php. You'll findone way here by the CodeIgniter frameworkanda more advanced explanation here. I recommend the CodeIgniter .htaccess guide first if you're inexperienced with .htaccess.2) Second, use the$_SERVERvariable in PHP to extract the URL. Probably with the help of the $_SERVER['REQUEST_URI'], you'll find '/username/' which you can then use to extract the user's data and serve it to them.Good luck and beware of URL injections using this method. | I have a small question to ask. Is it possible, via php or htaccess, to change a url like:miodominio.com/users.php?idu=xinto something likemiodominio.com/username?I want it to be Facebook style...Where "username" is the username chosen by idu = x. | Custom URL with PHP |
Use the .htaccess file for redirects. For example:# This allows you to redirect index.html to a specific url
Redirect /index.html http://example.com/location/Add some regex to match your rewrites and send to the dynamically created remote url. For example:# Dynamic redirect
RedirectMatch 301 yourUrl/\(.*)\$ http://external.com/someUrl.html?dynamicVal=$1That would send ...yourUrl/123 ->http://external.com/someUrl.html?dynamicVal=123 | I have changed the CMS to my site and it has rewritten the URLs to be more friendly but I have 20 pages which are linked on different sites across the web. I want when people click those old links for them to be redirected to their new respective posts.I was at first thinking of using a PHP array with a javascript redirect but now I'm thinking .htaccess mod-rewrite would be best.Whats the best way to have specific URLs redirect to their new URLs? | Looking for guidance rewriting specific URL's |
I've encountered this error when I've tried to use features of .htaccess not allowed in the ApacheAllowOverrideconfiguration parameter. If you have access to your Apache configuration, try setting this to the level you need, or maybeAllto allow full .htaccess capabilities. | I read a lot of server error 500 questions related to the famous .htaccess file...but I have still not found an answer to this error.I have a folder which i used to test the .htaccess file.=>http://localhost/xampp/example/I copied the .htaccess in the example folder and I get server error 500I checked in my error.log file and found this:.htaccess RewriteEngine not allowed hereBut I changed allAllowOverride NonetoAllowOverride Allin my httpd.conf file I also uncommented the lineLoadModule expires_module modules/mod_expires.soerror log says:ExpiresActive not allowed herewhat is actually happening??...how can I resolve this error??This is what I have in my .htaccess file now...<ifModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 days"
</ifModule> | Server error 500 when adding .htaccess file in the root folder |
.htaccesscan have multipleAuthUserFilelines:AuthUserFile /home/will/.htpasswd
AuthUserFile /home/wjholcomb/.htpasswd | I push my website to multiple servers where I have different usernames. I want to have a.htaccessfile that password protects a file regardless of which server I'm on.The issue is thatAuthUserFileonly takes absolute paths, so if I have:AuthUserFile /home/will/.htpasswdI get a server error on a box where my username is wjholcomb (and home directory is /home/wjholcomb/). | Referencing .htpasswd from accounts with different usernames |
Since standardrobots.txtis served from the root of your domain unless you can somehow reliably distinguish search engines from users I don't think what you are asking is possible.You could try filtering by user agent or possibly by IP range.Is there a reason why you don't want your users to not see what is in your robots.txt file? After all everything in that file is public. | I want to prevent users from accessing my robots.txt file but I still want search engines to read it. Is it possible?
If yes then how do I do it? I believe if I write following in .htaccess it will work but I am afraid it will also block search engines from accessing it.order deny, allow
deny from allThanks | Preventing direct access to robots.txt through .htaccess |
You can put this block of JS code inside separate.jsfile then include this file in every page:var sURL = (window.location.href + "").replace("http://", "");
if (sURL.indexOf("/#!/") < 0) {
if (sURL.substr(sURL.length - 1, 1) == "/")
sURL = sURL.substr(0, sURL.length - 1);
var arrTemp = sURL.split("/");
var sDomain = arrTemp[0];
var sPage = (arrTemp.length > 1) ? arrTemp[arrTemp.length - 1] : "news.html";
var sNewUrl = sDomain + "/#!/";
for (var i = 1; i < arrTemp.length - 1; i++)
sNewUrl += arrTemp[i] + "/";
sNewUrl += sPage;
window.location.href = "http://" + sNewUrl;
} | There is a page with two domains:www.exampleone.comwww.exampletwo.comI need a redirect to the start page:www.exampleone.comtowww.exampleone.com/#!/news.htmlwww.exampletwo.comtowww.exampletwo.com/#!/news.htmland last but not least, forevery pageI need a redirect like this, e.g.:www.exampleone.com/about.htmltowww.exampleone.com/#!/about.htmlwww.exampletwo.com/about.htmltowww.exampletwo.com/#!/about.htmlI don't really know how to solve that, should I use Javascript or .htaccess? for the last redirect in my example, it's better to use conditions right? but how?any ideas?Note: The contents are loaded with ajax, so the index page is always the same, that why the/#!/...thing.EDIT: straightforward, there are the live addresseshttp://www.jester04.chorhttp://www.jester04baden.ch, the startpage redirect is solved as you can see in the js file, but for the/#!/redirects I still need help, thank you. | I need help with redirects |
You can do a permanant redirection fromexample.com/test/totest.example.com. This will make sure everyone visit your site undertest.example.com. This would be more appropriate for your users.RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ http://test.example.com/$1 [r=301,nc]If you really want to show a 403 Forbidden, you can do thisRewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^test/(.*)$ / [r=403,nc] | I am trying to deny access to a sub-domain directory from people accessing directly rather get them to browse to the sub-domain directly. For e.g I want people to be able to go tohttp://test.example.comand nothttp://example.com/test. If they do show a 403 Forbidden error. Is this possible through htaccess ? Googled it but cant see anyone doing this. The main purpose being to disallow them from accessing the contents directly. Tried the following to no success.<Directory /test>
Order Deny,Allow
Deny from all
Allow from .example.com
</Directory> | Restrict access to web directory but allow sub-domain |
This won't work, becausemod_rewritedoes not expand variables in test patterns. Consequently, your expression will attempt to match the regular expression^%{foo}$, not^value_of_foo$.Additionally, the documentation forSetEnvalso makes a special note about order-of-processing in relationship tomod_rewrite. This actually does come into play here, despite the rules being applied later in the request handling than the scenario they're describing there. If you don't perform a rewrite that causes an internal redirection before testing against the environment variable you set, it will be blank.Assuming you set the variable correctly, a potential workaround is to do this, although I feel like it isn't foolproof:RewriteCond %{HTTP_HOST}#%{ENV:foo} ^([^#]+)#\1$ | I need something like this:SetEnv foo bar.baz
RewriteEngine On
RewriteCond %{HTTP_HOST} ^%{foo}$
RewriteRule ^(.*)$ http://www.foo/$1 [L]UPD:I have made as follows:SetEnv HOSTNAME_ENV testsite
RewriteEngine On
RewriteCond %{HTTP_HOST} ^%{ENV:HOSTNAME_ENV}
RewriteRule ^(.*)$ http://www.%{ENV:HOSTNAME_ENV}/$1 [L,R=301]But it doesn't work. %{ENV:HOSTNAME_ENV} is not defined. | Using custom environment variables in .htaccess |
You will probably have to use mod_rewrite. Assuming you place the .htaccess in the root directory, something like this should work.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^name-of-subfolder/.*$ / [R=302]
</IfModule>NB. I put 302, as it's always sensible to use for testing, 301 can make it a pain checking changes with your browser. Once it's working feel free to change to 302. | I'm trying to redirect all requests for a subdirectory and any files in it to the root directory, using htaccess. Currently I have redirect 301 /directory/ / But this redirects to the root with the file name requested appended to it.. ie www.domain.com/directory/this.html redirects to www.domain.com/this.html I don't want it to request the file at all. Is there a way to do this?Thank youKarl | How do I redirect a subdirectory and all files in it to the root using htaccess? |
Sure you can -#redirect mobile browsers
RewriteCond %{HTTP_USER_AGENT} ^.*iPhone.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*BlackBerry.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]
RewriteCond %{HTTP_USER_AGENT} ^.*Palm.*$
RewriteRule ^(.*)$ http://mobile.yourdomain.com [R=301]Taken fromhere | Is it possible to detect iPhone browser agent in .htaccess and redirect the user to the correct iPhone page? | Detect iPhone browser in .htaccess/apache and redirect to iPhone site |
This should work:RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [R=301]It will redirect all request without a subdomain to www.domainame.tld. | I found this code to force using www.RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]But i have many domain that pointed to same directory. So i need a version of this code for multiple domains. It must run on any domain, is it possible ? | Htaccess to force use WWW for mutlidomain |
I ended up usingrewriterule instead of errordocument:rewriteengine on
rewritecond %{request_filename} !-f
rewriterule ^(.+).jpg$ program.php?i=$1.jpg [L]The second line verifies that the file does not exist, so that existing images will be shown correctly. | I want to take requests formissing filesin a specific folder and redirect them toprogram.phpin that folder.This is a program I will use a lot in different places, and I would prefer to avoid specifying the name of the folder in the htaccess file.I have tried just putting:errordocument 404 program.phpbut the result is that the browser justprints out "program.php"and doesn't execute program.php.I understandwhythis is happening: based on the documentation athttp://httpd.apache.org/docs/2.0/mod/core.html, url's that don't begin with a slash or http are interpreted as a text message.The question is how to get around this limitation to be able to access the same folder. | How to use errordocument to redirect to a php file in the same folder? |
According toticket #2255for Django, you need admin access to httpd.conf in order to use Django with mod_python, and this is not going to change, so you may be dead in the water. To answer the basic question of how to modifysys.pathfrom.htaccess, you can use thePythonPathdirective in.htaccess. | The host I'm considering for hosting a Django site has mod_python installed, but does not have Django. Django's INSTALL file indicates that I can simply copy the django directory to Python's site-packages directory to install Django, so I suspect that it might be possible to configure Python / mod_python to look for it elsewhere (namely my user space) by modifying sys.path, but I don't know how to change it from .htaccess or mod_python.How do I modifysys.pathfrom.htaccessto allow mod_python to see Django?P.S. I can only access the site via FTP (i.e. no shell access). I realize that it sounds like I should just switch hosts, but there are compelling reasons for me to make this work so I'm at least going to try. | How do I modify sys.path from .htaccess to allow mod_python to see Django? |
Have it like this the given order.RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,NE,L]
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^contactus/$ /contact-us/ [R=301,NC,L]
RewriteCond %{REQUEST_URI} ^/system [NC]
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]RewriteEngine Onis not required multiple times in same .htaccess.Make sure to clear your browser cache before testing the change. | I am having a problem while redirecting a page whose URL was changed but I want old URL to be redirected to new. Here is.htaccessfile<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteEngine On
RewriteRule ^contactus/$ http://example.com/contact-us/ [R=301,L]Using mod_rewrite in the last line I am not getting redirected to new URL but when I use mod_alias(Redirect) rule I get redirected to new URL but Old URL gets appended to in it in this format.https://example.com/contact-us/?/contactus/I have searched Stack Overflow for solution to this problem and tried many similar scenarios but that didn't work. | Redirect 301 appending old URL with New URL |
After further research, it seems that PHP will always see the original URL in$_SERVER['REQUEST_URI']and not the target of the RewriteRule. (authoritative source needed here).By the way, the target of a RewriteRule is usuallya filethat will process the request, except if we use a [R] redirection flag, then in this case the browser will do a new request to the new URL (and the browser URL bar changes). | With this.htaccess:RewriteEngine On
RewriteRule foo/(.*) /foo-$1 # here I tried [L], [PT], [C], etc.
RewriteRule . index.php [L]I've tried all possible flags for the first RewriteRule, but always, this PHP code:<?php echo $_SERVER['REQUEST_URI']; ?>always echoes/foo/barinstead of/foo-bar, when accessinghttp://example.com/foo/bar. Why?How to have Apache's RewriteEngine also modify theREQUEST_URIthat will be seen by PHP?Note: I don't want [R] because a redirection would generate a new browser request, and change the URL displayed in the URL bar, which I don't want.See alsoRewriteRule when the substitution string is not a file path but an URL which should be processed by next rules. | How to use RewriteRule such that $_SERVER['REQUEST_URI'] is modified too for PHP? |
Put this at the beginning of yourpublic/.htaccessfile:AuthType Basic
AuthName "Please login."
AuthUserFile /home/my-project/.htpasswd
<RequireAny>
Require expr %{THE_REQUEST} =~ m#.*?\s+\/api.*?#
Require valid-user
</RequireAny>
// Rest goes here -->https://issues.shopware.com/issues/NEXT-4243(German)Basic translation for non-german users:Ticket: NEXT-4243 | auth_basic entry blocks backend accessThis ticket is not intended for implementation. Therefore it was closed. Reasons that lead to such a decision can include the complexity or the scope of the ticket, as well as possible sources of error caused by the changes.
[...]
The short-term solution here is not to create the authentication through the hosting configuration, but to create it via htaccess / htpasswd and then not subject requests to the URL "/ api" to the authentication in the htaccess | I wanted to protect a Shopware 6 installation with a htaccess auth protection. But when i set it up in the.htaccessfile in the/publicfolder i always get a "htaccess loop" in the backend (after login) and i can't use it anymore.I tried to exclude/apiand/adminbut i am not happy with that.
How can i solve the problem?/public/.htaccessAuthName "Prompt"
AuthType Basic
AuthUserFile /home/my-project/.htpasswd
Require valid-user
SetEnvIf REQUEST_URI "(/admin)" ALLOW
SetEnvIf REQUEST_URI "(/api)" ALLOW
<RequireAny>
Require env ALLOW
Require valid-user
</RequireAny> | How to protect the shop via htaccess? |
Could you please try following, based on your shown samples only. Please make sure you clear your browser cache after placing these rules into your htaccess file.RewriteEngine ON
RewriteCond %{REQUEST_URI} ^/category/([0-9a-zA-Z-]+)/?$ [NC]
RewriteRule ^(.*)$ category.php?name=%1 [L]
RewriteRule ^category/([0-9a-zA-Z-]+)/([0-9]+)/? category.php?name=$1&page=$2 [L]OR you could use it withoutRewriteCondtoo. Make sure you are putting either of these NOT both of them please.RewriteEngine ON
RewriteRule ^category/([0-9a-zA-Z-]+)/?$ category.php?name=$1 [L]
RewriteRule ^category/([0-9a-zA-Z-]+)/([0-9]+)/? category.php?name=$1&page=$2 [L] | I'm trying to write a mod-rewrite rule to handle pagination links on my site.I'd like my URL structure to be thishttps://example.com/category.php?name=category-linktohttps://example.com/category/category-link[without pagination]andhttps://example.com/category.php?name=category-link&page=2tohttps://example.com/category/category-link/2[with pagination]I've tried the following:RewriteRule ^category/([0-9a-zA-Z-]+)/([0-9]+) category.php?name=$1&page=$2https://example.com/category/category-linkisn't workinghttps://example.com/category/category-link/1is working2. am i able to redirectlocalhost/article/4/tolocalhost/article/4[here 4 is an id]Any guidance would be much appreciated. | .htaccess rewrite for category with pagination |
Just worked this out, should have had 'default-src: https:' in quotes, as in:Header set Content-Security-Policy-Report-Only: "default-src: https:"Hope this helps someone! | I have a domain hosted on a shared server with the following .htaccess headers:RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Header set Strict-Transport-Security: "max-age=31536000 ; includeSubDomains ;" env=HTTPS
Header set X-Frame-Options: SAMEORIGIN
Header set X-Content-Type-Options: nosniff
Header set X-XSS-Protection "1; mode=block"
Header set Referrer-Policy: strict-origin-when-cross-origin
Header set Content-Security-Policy-Report-Only: default-src: https:The first group of headers seem to work perfectly but when I include the last line I get a 500 internal server error and the site doesn't load. I don't have access to the server logs and the host support agents aren't trained in this field at all.Is there something I'm doing wrong here? Any help would be really appreciated! | 500 Internal Server Error when setting Content-Security-Policy header in .htaccess |
You can remove the defaultapiprefix by deletingprefix('api')from themapApiRoutes()method in your RouteServiceProvider, like below:App\Providers\RouteServiceProvider.phpprotected function mapApiRoutes()
{
// prefix('api) has been deleted
Route::middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}As for the api subdomain, I would just park it on top of the main domain. Then you don't have to worry about what directory it's pointed at. | I have a production server with some API's endpoints. I just want to make a more pretty system moving all API calls fromdomain.com/api/v1/xxxxxxto a subdomain likeapi.domain.com/v1/xxxxxxBy now, I just create the subdomain at cPanel: api.domain.com
then point that subdomain to thepublic_htmlfolder of laravel (I did the trick forpublic -> public_htmlrename 😁)Then add the route mapping domain in api.php://SubDomain Mapping
Route::group(['domain' => 'api.bachecubano.com'], function () {
Route::group(['prefix' => 'v1'], function () {
Route::get('categories', 'Api\AdController@get_categories')->name('api_get_categories');
});
});And try it atapi.domain.com/v1/xxxbut give me error. So the working solution isapi.domain.com/api/v1/xxxBut that its too ugly, I need to remove the second/api/url parameter.How do I tho this?PS: Put the subdomain mapping topublic_html/api, but that obviously crash with error 500.My mind says to me that the solution might be in .htaccess file, but In don't know much about it.Thanks | Laravel 5.8 use subdomain as API endpoint beside domain.com/api |
Change your rule to this:RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^moved/?$ https://my.example.com/#views/settings.php?id=2 [R=301,L,NE,NC]^(?:www\.)?example\.com$will matchwww.example.comandexample.comFlagNEis used forno escapingof#in redirected URLPatternmoved/?$matches/moved/and/moved, thus making trailing slash optional.Make sure to clear your browser cache or use a new browser for testing. | The URLshttps://example.com/moved/https://www.example.com/moved/should be redirected to the URLhttps://my.example.com/#views/settings.php?id=2via .htaccess.This is what I have tried:RewriteCond %{HTTP_HOST} ^example.com
RewriteCond %{REQUEST_URI} moved$
RewriteRule (.*)$ https://my.example.com/#views/settings.php?id=2 [R=301,L]However it seems not to work. I guess the reason is the #hashtag within the URL where I want to redirect to (it marks a comment within .htaccess).How to redirect this correctly? | Apache .htaccess: Redirect to an URL containing a hashtag |
Opencart 3.x SEO URL issue SOLVED Just Upload extension or follow this steps.its working fine for product_id, category_id etc...but for any pages its not workingFor Fix with Extension Click Herehttps://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=31993ORTHIS STEPS ARE FOR DEVELOPERS ONLY FOR WHOM DON'T WANT TO INSTALL PLUGINnow i m going to see you how we fix that opencart 3.x seo issue.step 1 - open your ftp and go to this path catalog/controller/startupstep 2 - open seo_url.php for editstep 3 - line no 87 we have to put one more else ifcode :} elseif ($key == 'route') {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE `query` = '" . $this->db->escape($value) . "' AND store_id = '" . (int)$this->config->get('config_store_id') . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'");
if ($query->num_rows && $query->row['keyword']) {
$url .= '/' . $query->row['keyword'];
unset($data[$key]);
} else if ($data['route'] == "common/home") {
$url .= '/';
}end code :step 4 - rename .htaccess.txt to .htaccessTHIS VIDEO FOR DEVELOPERS ONLYhttps://youtu.be/bS1N_twvL4oAny Theme Compatible.Frontend Demohttp://demo.sainent.comAdmin Demohttp://demo.sainent.com/adminUsername: demoPassword: demo | opencart 3 .x SEO URL issueIn opencart 3 .x SEO URL Working for product id, category id, information id but for page common/home, account/login, account/account etc not working.i had changed it from htaccess.txt to .htaccessChange from System > Setting > Serveri m adding in SEO url from admin in Design > SEO UrlStill not workingCan you help me guys.Thank You, | Opencart 3 .x SEO Url not working for route=information/contact, route=account/login |
Try moving the following lines at the start of.htaccessfileRewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | I want to force redirect OpenCart store to its WWW version with opencart.SEO URL SettingsRewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]This is the htaccess part for the redirect and it works but the smart URL now arehttps://www.example.com/index.php?route=the-name-of-the-productand it should behttps://www.example.com/the-name-of-the-productAny idea how to fix this problem with the smart urls?
Am I doing the redirect wrong or the problem is other? | OpenCart htaccess redirect to WWW and SSL |
You can use thissinge ruleas very first rule inforums/.htaccessinstead of top level .htaccess:RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.(?:com|net))$ [NC]
RewriteRule ^.*$ http://forums.%1/$0 [L,R=301,NE]For root .htaccess use this rule asyour first rule:RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.(?:com|net))$ [NC]
RewriteRule ^forums(/.*)?$ http://forums.%1$1 [NC,L,R=301,NE] | On my website, I am interested in moving my forums from a subdirectory to a subdomain. The forums are currently located atexample.com/forums, and I want to move them toforums.example.com. After the move, I want to use htaccess to 301 redirect all forum traffic to the subdomain, but the problem is that I have two TLDs for my site, a.comdomain and a.netdomain.I am currently trying to redirect traffic using this:RewriteCond %{HTTP_HOST} !=forums.example.net
RewriteRule ^forums(/(.*))?$ https://forums.example.net/$2 [L,R=301]
RewriteCond %{HTTP_HOST} !=forums.example.com
RewriteRule ^forums(/(.*))?$ https://forums.example.com/$2 [L,R=301]This only half-works. Regardless of which TLD I visit, it always redirects me toforums.example.net, even if I am visiting fromexample.com/forums, in which case I want it to go toforums.example.com. How could I achieve this? | htaccess Rewrite URL based on TLD |
order deny,allow
deny from all
allow from ipis deprecated.UseRequire ip ip.addressinstead.Reference. | I'm trying to set up where I can deny all IPs and allow only certain of them in. But the only thing that is working is IP4s and not either IPv6 or domains.Please let me know if I'm missing something. It doesn't seem to work no matter what permutation.order deny,allow
deny from all
allow from 67.93.23.3
allow from 127.133.23.33
allow from 2632:336:3639:2b30:b347:33d4:f135:f313
allow from domain.com<RequireAll>
Require all denied
Require ip 64.91.24.3
Require ip 2442:346:8355:8fa0:1110:3f47:198f:e80d
</RequireAll> | .htaccess Deny From All - IPv6 & Domains Not Allowing |
I'm not sure ifupgrade-insecure-requestsorblock-all-mixed-contentwill generated events because they prevent the bad events from happening in the first place.I could be wrong about the reasoning, but I do knowblock-all-mixed-contentdoes not generate violations.For block-all-mixed-content, it explicitely will not send a report. Fromhttps://www.w3.org/TR/mixed-content/#strict-opt-in:This directive has no effect when monitored. This directive’s only
effect is to set a policy flag on the protected resource; it will
therefore never be violated, and has no reporting requirements. | What I'm trying to achieve:Both upgrade all HTTP requests within the page to HTTPS and report/log the events.The server supports both HTTP and HTTPS.Test HTML page. Note the hardcoded HTTP protocol in<img><html>
<head>
</head>
<body>
<img src="http://example.com/testimage.png" />
</body>
</html>According to theW3C documentation, I set up my .htaccess like this:Header set Content-Security-Policy "upgrade-insecure-requests; default-src https:"
Header set Content-Security-Policy-Report-Only "default-src https:; report-uri https://report-uri.io/report/..."When I callhttps://example.com/testpage.html, it loads the image over HTTPS but doesn't report the event.What am I missing? | Content security policy header - both upgrade insecure requests and report the events |
Have it like this:RewriteEngine On
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^admin/(.*)$ admin/index.php?action=$1 [L,NC,QSA]
RewriteRule ^(.*)$ index.php?action=$1 [L,QSA] | I read tons of topics about this here on SO, but for some reason it not works for me, and I am totally confused. I know, I mess up something, I just cant figure it what.I have a site, and theindex.phpis calling the router, and show the content that I want.I've created an admin' page, and I want the webserver to use the/admin/index.phpfor every request what is starting with/admin/Here is what I try:RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*)$ admin/index.php?action=$2 [L,NC]
RewriteRule ^(.*)$ index.php?action=$1 [L]I echoing some information from bothindex.phpto see which handles my request.If I am writinghttp://localhostit saysFrontend.When I tryhttp://localhost/admin/it saysFrontendagain.If I am moving the admin' line below the first rule like this:RewriteRule ^(.*)$ index.php?action=$1 [L]
RewriteRule ^admin/(.*)$ admin/index.php?action=$2 [L,NC]thenhttp://localhost/admin/saysAdminwhat is actually good!But if I tryhttp://localhost/admin/userswhat is actually not there, because the admin's router should handle that, it saysFrontend.How should I set.htaccessto use/admin/index.phpin all cases, where ahttp://localhost/admin/in the URI? | .htaccess in subfolders |
You could experience this redirect loop if yourDirectoryIndexis set toindex.html(as the first option), which is likely to be the default setting on your server.Basically, when you access a directory, eg.http://example.com/(the root directory) then theDirectoryIndexdirective tells the server which file to serve (via an internal rewrite). eg.http://example.com/index.html. This then seeds the redirect loop.Since you are using WordPress, you could change this in .htaccess to favourindex.phpinstead. For example, at the top of your .htaccess file:DirectoryIndex index.php index.htmlHowever, you could also solve this by using mod_rewrite (which is probably preferable). In fact, since WordPress already uses mod_rewrite (eg.RewriteRuledirective) then you should also be using mod_rewrite for your redirects, not mod_alias (eg.Redirectdirective). You should not mix redirects from both modules in .htaccess since you can easily get conflicts. Different modules execute at different times, regardless of their order in .htaccess.By using mod_rewrite you can avoid a redirect loop by checking againstTHE_REQUEST. For example:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html [NC]
RewriteRule ^index\.html$ / [R=301,L] | I recently changed my website from static html to Wordpress, and in doing so I've been redirecting all of my former and nonexistent pages with my .htaccess file whenever Google shows me a crawl error. I've been successful in redirecting all crawl errors until today. My oldindex.htmlis throwing a crawl error and when I use:Redirect 301 /index.html http://www.example.com... I get this from my browser:Too many redirects occurred trying to open www.example.com. This might occur if you open a page that is redirected to open another page which then is redirected to open the original page.*I have since removed the above redirect from my.htaccessfile and will just live with the crawl error if I can't get this resolved. But I'm thinking somebody knows how to solve this and if so, I'd really appreciate it if you'd let me know how. | Redirecting nonexistent index.html to home page in Wordpress is causing too many redirects in browser |
Try this rule:RewriteEngine On
RewriteCond %{HTTP_COOKIE} _sTrxIT=[^;]+ [NC]
RewriteRule ^ http://www.google.com [L,R=302] | How do I do the validation, that whenever a cookie isset. This user will be redirected to the given page.This is what I currently have (which is redirecting the user, if there is NO cookie set, but I want the opposite):RewriteEngine On
// Redirect user, if cookie EXISTS, and if not, ignore this whole code.
RewriteCond %{HTTP_COOKIE} !_sTrxIT=(.*);? [NC]
RewriteRule ^ http://www.google.com [R]It would be a pleasure for me, if anyone had some suggestions! | Htaccess - Validate if Cookie ISSET |
RedirectMatchis directive frommod_alias. What you need isRewriteRulehere:RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?projetomedicina\.com\.br$ [NC]
RewriteRule ^(site)?/?$ /portal [L,R=302,NC]Make sure to clear your browser cache before testing this change. | I wrote this redirect rules for my primary domain:RewriteEngine on
RewriteCond %{HTTP_HOST} ^projetomedicina\.com\.br$ [OR]
RewriteCond %{HTTP_HOST} ^www\.projetomedicina\.com\.br$
RewriteCond %{REQUEST_URI} ^/site[/]?$
RewriteCond %{HTTP_HOST} !^(lojinha_\.projetomedicina\.com\.br$ [NC]
RedirectMatch 301 ^/$ /portal
RedirectMatch 301 ^/site/$ http://projetomedicina.com.br/portalBut then I try to access one of my subdomains:http://lojinha.projetomedicina.com.brit redirects to /portal.How can I modify my .htaccess in order to do not allow redirects from my subdomain? | Do not redirect subdomain in htaccess |
The problem is that/my/sample/pagegets trapped by the last rule and the rewrite engine then loops. This is what's happening:Request is made tohttp://www.example.com/my/sample/pageFirst rule is skipped,%{HTTP_HOST}starts with "www."Second rule is skipped,%{REQUEST_URI}starts with/my/sample/pageThird rule is applied, request isn't for an existing filename or directory. The request URIis now/index.php.Rewrite engine loopsFirst rule is skipped,%{HTTP_HOST}still starts with "www."Second ruleis applied,%{REQUEST_URI}which is now "/index.php", isn't/my/sample/page, request gets flagged for redirect tohttps://www.exmaple.com/index.php.Rewrite engine loopsRequest is flagged for redirect so is sent through the processing pipeline.Try changing the second rule from:RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/my/sample/page
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]toRewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/my/sample/page
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]This way, when the rewrite engine loops, the%{THE_REQUEST}variable would still beGET /my/sample/pageand thus the condition still fails. | I want to get the following things done with my .htaccess:Non www to wwwhttp to https except for page/my/smaple/pageExecute index.php in case the filename is not a file or directoryThis is how it looks at the moment:RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/my/sample/page
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]If I try to accesshttp://www.mydomain.tld/my/smaple/page, I am getting redirected tohttps://www.mydomain.tld/index.php. Everything else works though. My .htaccess knowledge is pretty low so please explain me what's wrong. | .htaccess redirect to https except on one page |
You typically just add the rules to your wordpress rules. They go before wp rules.RewriteEngine On
#rewrite http to https and add www. All cases covered
RewriteCond %{HTTPS} !^on [OR]
RewriteRule %{HTTP_HOST} ^exmaple\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress | I already got an SSL certificate.
I got Wordpress installed see folder structure in my hostgator file manager below:I already putdefine('FORCE_SSL_ADMIN', true);inwp_config.phpWordpress General settings:
WordPress Address (URL):https://www.domain.com/blogSite Address (URL):https://www.domain.compublic_html
-> blog (inside is the wordpress installation)
database structure
-> wp_options
-> siteurl: https://www.domain.com/blog
-> home: https://www.domain.comI tried hostgator cpanel redirects, but not works.I also tried some of the solutions editing.htaccesswhile searching in google.Maybe I missed on something regarding with the folder structure..htaccess:# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPress | How to redirect http://domain.com to https://www.domain.com? |
Try this one:RedirectMatch ^.*\/(\d+)\-.*$ products.php?p=$1The rewrite rule matches the number inside a capture group and then substitutes it for $1. | I have a bunch of products listed athttps://www.example.com/all/products/foldername/1234567890-ProductDescriptionA-456.html
https://www.example.com/all/products/foldername/7654321-SomeOtherDesc-B123.html
https://www.example.com/all/products/foldername/93939393-anotherthing-F93939393.htmland I want these to be redirected tohttps://www.example.com/products.php?p=1234567890
https://www.example.com/products.php?p=7654321
https://www.example.com/products.php?p=93939393respectively. Is there an htaccess rule to do string operations on a matched parameter? For example, if I had to convert my URL using Python, it would look like this:def make_new_url(old_url):
product_id = old_url.split('/')[-1].split('-')[0]
new_url = 'https://www.example.com/products.php?p=%s' % product_id
return new_urlIn the old URLs, the product ID is found after the last "/" and just before the first "-". Another regular expression based rule that would work would be:\/(\d*?)\-Any thoughts as to how to accomplish this inside an Apache htaccess file? | htaccess redirect URL using partial value of string parameter |
WordPress modifies the .htaccess file if necessary, but only the content of the#BEGIN ... #END WordPressblock. Add your own entries outside of this block and WordPress will not touch them.Another option is to remove write access for the webserver to the file, so WordPress can't modify it directly. WordPress will tell you to change the file if necessary. | I have website powered by WordPress and I also have .html files inside WordPress root folder since WordPress will not allow .html files , I have written .htaccess code to open .html files as well as wordPress pages but the problem is .htaccess file is modifying automatically and .html files will not workWhat is causing this ?my .htacces code | .htaccess file modifying automatically |
You can use:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^path_to_file/(file1|file2|file3)\.html$ - [L,NC,G]
</IfModule>FlagG(Gone) is equivalent ofR=410. | Our company's SEO expert asked me to set some particular pages to 410 - status gone.I have searched about declaring 410 urls in .htaccess but I'm very confused, cause I don't understand if I have to redirect google bots to another url or just make a statement (just that these urls are missing, and don't search about them, they're gone). I'm also confused about how to do that, cause I've seen many differect codes reffering to 410, and I don't understand which one fits my case.I think that the following code is what I need, but I'm not sure. Could you please check the following lines and tell me if they're correct? Do they set these urls to 410-status-gone?<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 410 /path_to_file/file1.html
Redirect 410 /path_to_file/file2.html
Redirect 410 /path_to_file/file3.html
</IfModule> | Set 410 - STATUS GONE for specific url |
+25You have to create a'bypass rule'at the top to skip the subsequent rules if the request is for the addon (in our case the www.addon1.com).Add towww.mainwebsite.com's.htaccessfile at the top the following:RewriteCond %{HTTP_HOST} ^(www\.)?addon1\.com
RewriteRule .* - [L]
...*info for [L] rulehere.EXPLANATIONThis tellsmod_rewriteto quit processing right here if the requested domain is addon1.com or www.addon1.com.To help you more i tried the senario at this excellent online rule test tool:http://htaccess.madewithlove.be/and i give you the results.1st Type: www.addon1.comResult: Stop processing and other rules below could not met!2nd Type: www.whatever.comResult: Continue processing and could met other rules!Finally, you can add whatever rule you want bellow this piece of code and it will work!
Be carefull,we made changes only to the domain.htaccessfileHope it helps! | I have a hosting service with two addon domains.All was working well till few weeks ago.If I enter www.addon1.com, it redirects to www.mainwebsite.com. Same happens for www.addon2.com.But if I enter www.addon1.com/index.php, it loads properly.I really do not know what the problem is.Is there anything I can do ( htaccess or something else ) to ensure that www.addon1.com does not redirect to www.mainwebsite.comEDITContent of www.addon1.com .htaccessOptions -IndexesContent of www.mainwebsite.com .htaccessOptions -Indexes
Redirect 301 /index.html http://www.mainwebsite.com/index.php
Redirect 301 /portfolio.html http://www.mainwebsite.com/portfolio/index.php
Redirect 301 /services.html http://www.mainwebsite.com/services/index.php | Addon domains redirect to main domain |
Two things here: (a) getting the cronjob to run, (b) access restriction.CronjobNew crontab entry:*/10 * * * * /usr/bin/php /somewhere/www/cronjob.phpSet correct permissons on cronjob.php:Execute flag:chmod +x /somewhere/www/cronjob.phpAccess RestrictionIn general, it is a good practice, to place the script files for cronjobs outside of thewwwpath.If you really need to place them inwww, then you might protect them with an access restriction. For the webserver Apache, this would work via .htaccess, like so:.htaccessinside/somewhere/www/:<Files "cronjob.php">
Order Allow,Deny
Deny from all
</Files>This protects the file cronjob.php from outside access, but allows cron to execute the file.If nothing works, follow my step by step guide:https://stackoverflow.com/a/22744360/1163786 | have a cron job that is located in a folder in the normal directory.I am trying to not allow access to this file by anyone else EXCEPT my server for running the cron job.I tried:order deny,allow
deny from all
allow from 127.0.0.1But no luck. I have gone down the root of putting the cron job outside the web root but i could not get it to run no matter what me and my host tried.Thanks. | Allow server to run cron jobs but block access to normal user with .htacess |
Keep your/MyApp/admin/.htaccesslike this:<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /MyApp/admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!web/).*)$ web/$1 [NC,L]
</IfModule> | I am using the crud-admin-generator (http://crud-admin-generator.com/) to generate a quick backend for my web app, which is based on the silex framework.My app structure is:MyApp
->index.php
->some_other_files
->...
->admin (the crud-admin-generator git clone)
->gen
->src
->vendor
->web
->controllers
->resources
->views1) When I access the admin I currently need to usehttp://localhost/MyApp/admin/web. I want to remove the/webpart.
I tried creating a customhtaccessin theadminfolder with:<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>But I keep getting an error:The requested URL /web/index.php was not found on this server.2) The generated admin panel uses the silex framework, is there a easy way for me to use the doctrine component or the framework itself for my frontend as well (files outside the admin folder)? Would I need to manually change the routing paths of all the generated admin files? Sorry if I sound confused. | How do I remove the "/web" from my URL? |
The speed implications of using either is negligible and you won't notice a difference. That being said, you should use the right tool for the job.Doing a simple redirect, you should use a Redirect instead of using Mod_Rewrite. That example is something a Redirect should take care of. When you need to start doing more complex things you can think about using Mod_Rewrite.Even with 1000 or 10,000 redirects you're not really going to notice a big difference. However it will use more RAM. Probably a few MB's if that.So to answer your question, it really wont have a real impact but use the right tool for the job.This should help.When not to use mod_rewrite | I'm curious to know if there is any difference in speed between RewriteRules and Redirect within a .htaccess rule on Apache.To my mind, RewriteRules can often be complex regex expressions which I assume have overhead (even if it's incredibly small) compared to Redirect that would be simple string matching(?)So, if I had:RewriteRule ^mytestpage\.html$ http://www.google.com [R=301, QSA]vsRedirect 301 /mytestpage\.html http://www.google.com/I'm probably never going to notice a difference, but what if I had 1000 unique redirects? or 10,000? Would it be adventagous to use one over the other? | Speed implications of using Redirect vs RewriteRule |
The problem was with the ssl config file in the server. Allow Override needed to be set to All under the secure virtual host at port 443. After changing that, the following code in the root htaccess file allowed me to force https across the whole website except a specific folder:RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !/webservice [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]So any request to http would go to https. However I still needed to explicitly change requests to https on my specified folder to redirect to http, so added the following code after the above:RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} /webservice [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]Bullet proof. | I've tried implementing a number of suggested solutions to this problem but can't get anything to work.I am using 2 .htaccess files, one in my root directory which reads as follows:RewriteEngine on
RewriteBase /
RewriteRule ^(webservice|api) - [L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.domain.com%{REQUEST_URI} [R=301,L]This redirects all traffic to the main website through https which I need.However in a subdirectory I want to disable the reroute and force all requests that go to this directory through http. The .htaccess file in /webservice/rest/ reads:RewriteEngine On
RewriteBase /webservice/rest/
RewriteCond %{HTTPS} on
RewriteRule (.*) http://www.domain.com/webservice/rest/%{REQUEST_URI} [R=301,L]
RewriteRule ^testingPost/?$ testingPost.php [NC]
RewriteRule ^([a-zA-Z0-9\_\-]+)/?(\?([a-zA-Z0-9\_\-\=\?\&]))?$ otherfiledirect.php?method=$1¶ms=$2 [NC]There are a few redirects taking place, but the 3rd and 4th line in the 2nd htaccess don't seem to be doing anything - can anyone see what I'm doing wrong and how to keep https on the main site but force http on any url below /webservice/rest/ ??Cheers | htaccess https in parent but http in subdirectory |
I was faced with a very similar situation recently.
To save the 404 from all the results at Google & linked sites, I kept the old route but pointed it at a new controller/function. Theis function manages the the 301 redirection.public function oldurl_to_newurl()
{
$newURL = LogicToGetNewURL
redirect($newURL,'location',301);
}Using the segments from the old URL, I query the database(if needed) and create the new URL. It then redirects the users accordingly. This was I am also able to track the some metrics for my analytic. | I have a codeigniter site, for which i am doing SEO, so the issue is most of the urls are cached in search engines, what my old url is/product/details/productname/productidMy new urls will be/tours/cityname/productnameI want for my old urls to be redirected to new with 301, and new product url not to be redirected with 301 as they are new and will have the same url structure, as I search on codeigniter site about url routing in router.php, which gives an example for redirection as$route['product/(:num)'] = "catalog/product_lookup_by_id/$1";I think that this where i can make the change but how can i do a 301 in this pattern, by using header or is there a better way of doing this ? | codeigniter 301 redirect with router for old url and remaning no redirect |
This is how you use.phpfine inHeaderNamedirective:AddType text/html .php
Addhandler application/x-httpd-php .php
HeaderName /includes/header.php | I have assignedHeaderName path/.../head.htmlin .htaccess,in which my php page (as it is set in action tag in a form at head.html) is sending output from html to another page (that's obvious), and to display output on the same page, I must build my php code with html on the same page, and save it as .php extension, but HeaderName in .htaccess is not accepting .php extension,
also I amstrictly not allowedto usesuperglobal variables(like SESSION) !!
please help,, | HeaderName in .htaccess do not uses .php extension |
yes, mostly used in frameworksan approach called using a front controllerex: your front controller is index.phpyour page links are generated as a fashion of .../index.php/nything/url.phpbut the actual link is .../this/is/long/url.phpthe front controller extract the page information the client requested and show the relevant page related to itread more :http://en.wikipedia.org/wiki/Front_Controller_pattern | Is it possible to shorten a url without using htaccess file?
for example I have this url.this/is/a/very/long/url.phpchange toshort/url.phpI hope I can get good answer THX guys:) | Is it possible to REWRITE a URL without htaccess file? |
Change your regex to allow spaces:RewriteRule ^StorageList\.php/([a-z]+)/([0-9]+)/(.+?)/?$ StorageList.php?type=$1&users_id=$2&parts_section=$3 [L,NC,NE,QSA] | I must (want ;) use spaces in URLs. I make "cute" URLs via htaccess:RewriteRule ^StorageList.php/([a-zA-Z]+)/([0-9]+)/([0-9a-zA-Z%+-]+)$ StorageList.php?type=$1&users_id=$2&parts_section=$3 [L]But when I go to StorageList.php/Point/21/Ford Fiesta, my script don't get variable data. | HTACCESS - use spaces in URL |
+150Replace your existing code with this:Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.market\.mysite\.com$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/+.+?\.(png|jpe?g|bmp|gif|swf|css|js)[\s?] [NC]
RewriteRule ^ http://market.mysite.com%{REQUEST_URI} [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]Test in a different browser or clear your existing browser cache. | I cant understand why but:RewriteCond %{HTTP_HOST} market\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^market\.mysite\.com$ [NC]
RewriteCond %{REQUEST_URI} \.(png|jpe?g|bmp|gif|swf|css|js)$ [NC]
RewriteRule ^(.*) http://market.mysite.com/$1 [L,R]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]Works as expected. Redirecting images to an other domain. But this one:RewriteCond %{HTTP_HOST} market\.mysite\.com$ [NC]
RewriteCond %{HTTP_HOST} !^market\.mysite\.com$ [NC]
RewriteCond %{REQUEST_URI} !\.(png|jpe?g|bmp|gif|swf|css|js)$ [NC]
RewriteRule ^(.*) http://market.mysite.com/$1 [L,R]
RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]Will redirect all no matter what. What I want to see is to redirect all except images.
What I am trying to do in my rules above is to redirect all sub-domains of market.mysite.com to market.mysite.com if it wasn't market.mysite.com and if it wasn't an image. In another word:cdn.market.mysite.com -> market.mysite.com
cdn.market.mysite.com/blahblah.html -> market.mysite.com/blahblah.html
cdn.market.mysite.com/blahblah.png -> NO REDIRECT
market.mysite.com -> NO REDIRECTI use wildcard sub-domain so all of my market sub-sub-domains will use same directory. And then responding to all of requests by one php file. index.phpThanks, | Redirect everything except images |
If you are running PHP in "CGI mode" and not as an Apache module, then usingphp_valueas such will throw that "Internal Server Error". In such case, setupload_max_filesizeinphp.ini. | I am using the code in .htaccess files like this:<Directory "/home/star/public_html/test">
AllowOverride All
Options None
Order allow,deny
Allow from all
</Directory>
php_value upload_max_filesize 32MIt is giving the Internal Server Error. Can any one help me to correct it.Thanks in advance | php_value is not working in .htaccess files |
You can certainly use Javascript to make itsite.com/search/developer. For the extreme rare case when Javascript is disabled you can let them submit regular HTML form with the final URL assite.com/search.php?kword=developer.Good news is that using mod_rewrite you can handle both the cases to always have pretty URL in the browser.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 /
# internal forward
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^search/(.+?)/?$ /search.php?kword=$1 [L,QSA,NC]
# external rewrite
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+search\.php\?kword=([^\s]+) [NC]
RewriteRule ^ /search/%1? [R=302,L]Once you verify it is working fine, replaceR=302toR=301. Avoid usingR=301(Permanent Redirect) while testing your mod_rewrite rules. | So I'm working on a self project of mine and it is related to
job searching. I want the urls to appear as:
site.com/search/developer where developer is
the search keyword obviously. Now the thing
is that as normally when I click search (the
submit button does it's job) and the url appears
as:
site.com/search.php?kword=developer and Im sure
htaccess rewrite cannot change the way php forms
behave and how they format the url.Now I have an idea to use javascript so that when
user types a keyword, i take that and redirect the
page via js to site.com/search/[keyword] but I'm
UNSURE if this is a good idea (considering disabled
javascript cases).Is there any decent/recommended way to achieve what
I'm trying to achieve, I know there is because I have
seen some big websites do it only I dont know what's
the best way to do it.Thank you in advance. | php search form and url rewrite/formatting |
If you are using the latest version of the puppetlabs-apache module
I see an *allow_override* attribute and notoverridehttps://github.com/puppetlabs/puppetlabs-apache#allow_override | I'm trying to enable .htaccess files in Apache using Vagrant and Puppet. When I add the "override" parameter to my vhost config and run "vagrant up", I get an error:Invalid parameter override in [...]When I remove that line, the vm boots perfectly and runs. Except, .htaccess files are ignored.Here's my vhost config:apache::vhost { 'local.testsite':
server_name => 'local.testsite',
serveraliases => [],
docroot => '/var/www/',
port => '80',
env_variables => [],
priority => '1',
override => ["All"],
}Why am I getting this error and how can I fix it? | Enabling .htaccess files via puppet |
First of all it should bephp_flag display_errors OffNot likephp_value display_errors OffHowever, our servers run PHP in "CGI mode" as recommended by the PHP developers (not as an Apache module), so you can't use "php_value" or "php_flag" commands in .htaccess files. If you try to do so, you'll see an "internal server error" message. | I installed new XAMPP version 1.8.1 for windows with Apache 2.4.3 and PHP 5.4.7.None of my sites are working, returning HTTP Error 500 (Internal Server Error). I traced the reason to this .htaccess linephp_value display_errors offWhen I comment it, site works. I have other php_value command's that works just fine eq.php_value error_reporting -1.Google for solution, people say PHP must be loaded as Dynamic Shared Object (DSO) aka. Apache module. Which in my case is so (httpd-xampp.conf):LoadFile "/xampp/php/php5ts.dll"
LoadModule php5_module "/xampp/php/php5apache2_4.dll"So this is not what is creating a problem.I would prefer solution that keepsphp_value display_errors offinside .htaccess file for the sake of other people it my team.pls help== NEW DEVELOPMENT ==After commenting unrelated parts of .htaccess file that was using mod_expires.c and was badly writen, aka. correct way is to put it in if example:<IfModule mod_expires.c>
ExpiresActive On
<FilesMatch "\.(gif|jpg|jpeg|tif|tiff|bmp|png|js|css|ico)$">
ExpiresDefault "access plus 10 years"
</FilesMatch>
</IfModule>500 error was gone and php_value instructions work.So if you are in similar situation comment or remove all unrelated lines and try to pint point where the problems is. | .htaccess php_value display_errors settings breaks with error 500 |
%5c represents a \ character. Since you are seeing %5c%22 that is the equivalent of \" which is the way that a " would be escaped in a php program if it occurred within a string quoted with double quotes. I suspect that whatever is creating the urls has an incorrectly escaped character (maybe the string is quoted with single quotes). You need to track down where the php error is and when fixed, this problem should go away. | A joomla site without sef url is showing %5C%22 between most of the url as per webmaster. Due to this the webmaster showing duplicate urlDuplicate url as showin in webmasterhttp://www.xyz.com/%5C%22/index.php?option=com_newcar&view=price&Itemid=2
http://www.xyz.com/%5C%22/index.php?option=com_newcar&view=details&Itemid=2&id=41&vid=39When clicked on them, url turns out to be :-http://www.xyz.com/%5C"/index.php?option=com_newcar&view=price&Itemid=2
http://www.xyz.com/%5C"/index.php?option=com_newcar&view=details&Itemid=2&id=41&vid=39Have tried several htaccess combinationsRewriteCond %{REQUEST_URI} ^.*/%5C%22.*$
RewriteRule .* index.php [R=301,L]
RewriteCond %{REQUEST_URI} ^.*/%5C".*$
RewriteRule .* index.php [R=301,L]But unable to remove itThe correct urls arehttp://www.xyz.com/index.php?option=com_newcar&view=price&Itemid=2
http://www.xyz.com/index.php?option=com_newcar&view=details&Itemid=2&id=41&vid=39any suggestions | Webmaster showing duplicate urls with %5C%22 parameter |
The generic rule has been moved to the bottom, and theREQUEST_FILENAMEconditions moved beneath the static redirects. Further, I have added a/?to match an optional trailing slash on each of the specific redirects. Finally, the generic rule is improved not to use.*, but rather to match everything up to the first/in a less greedy way. Then it uses.+after the/to make sure at least one character is present. Urls with a trailing slash would therefore not match it. If you have some generics without asecond=, change back to.*.All of these work correctly in the htaccess tester.RedirectMatch 302 /construction.html http://www.{website}.com/construction-services
RedirectMatch 302 /construction/endless-pools.html http://www.{website}.com/construction-services/endless-pools
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^signup-free/?$ /signup-free.php [L,NC]
RewriteRule ^about/?$ /content.php?page=1 [L,NC]
RewriteRule ^links/?$ /content.php?page=2 [L,NC]
RewriteRule ^portfolio/?$ /portfolio.php [L,NC]
RewriteRule ^our-stores/?$ /our-stores.php [L,NC]
RewriteRule ^contact/?$ /contact.php [L,NC]
RewriteRule ^products-list/?$ /lists.php?action=products [L,NC]
RewriteRule ^services-list/?$ /lists.php?action=services [L,NC]
# PRODUCT AND SERVICES
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^([^/]+)/(.+)$ /rewrite.php?sub=$1&second=$2 [NC] | I have the following rules, the one "our-stores" redirects to a different place than the other "PLAIN PAGES" rules:Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RedirectMatch 302 /construction.html http://www.{website}.com/construction-services
RedirectMatch 302 /construction/endless-pools.html http://www.{website}.com/construction-services/endless-pools
# PRODUCT AND SERVICES
RewriteCond %{REQUEST_URI} !\.html$
RewriteRule ^(.*)/(.*)$ /rewrite.php?sub=$1&second=$2 [NC]
# PLAIN PAGES
#RewriteRule ^/$ /index.php [L,NC]
RewriteRule ^signup-free$ /signup-free.php [L,NC]
RewriteRule ^about$ /content.php?page=1 [L,NC]
RewriteRule ^links$ /content.php?page=2 [L,NC]
RewriteRule ^portfolio$ /portfolio.php [L,NC]
RewriteRule ^our-stores$ /our-stores.php [L,NC]
RewriteRule ^contact$ /contact.php [L,NC]
RewriteRule ^products-list$ /lists.php?action=products [L,NC]
RewriteRule ^services-list$ /lists.php?action=services [L,NC]When I type/our-storesapache redirects to:/our-stores/?sub=our-stores&second=I don't get it because the rest (signup-free, about, links, portfolio... and so on) are working fine.Can anybody help me with this one?Thank you. | Why if I put a "-" dash in a rule in my htaccess doesn't work? |
Learn about.htaccessThere are a lot of generators for.htaccessand you can use one of them. The best thing to do is, using a.htaccessfile, create the paths this way:mywebsite.com/entry.php?title=My Title&content=This is my blogChange them to:mywebsite.com/My Title/This is my blogAnd the code for the same is:RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /entry.php?title=$1&content=$2 [L]Websites offering generators:.htaccess redirectMod Rewrite GeneratorSearch Engine Optimization Tools » mod_rewrite rewriterule generator | Closed.This question isoff-topic. It is not currently accepting answers.Want to improve this question?Update the questionso it'son-topicfor Stack Overflow.Closed11 years ago.Improve this questionI'm trying to create a blog ..and for every entry I have a template page called entry.php
I create the pages by creating a link from my home page like thismywebsite.com/entry.php?title=My Title&content=This is my blogThis link is passed to entry.php and a page is generated on the fly based on the link i wrote but search engines wont index these.Do I really have to create a unique page for every entry I create?Do sites like youtube have individual pages for every single video or are they generated dynamically like im trying to do. If so how do the videos show up in search results?Ive heard something called .htaccess or sitemap.xml can be used for this I have no idea what these are though. | How can I get search engines to index dynamically generated pages [closed] |
Try to disable the default Apache CentOS welcome page:#
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL. To disable the Welcome page, comment
# out all the lines below.
#
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /error/noindex.html
</LocationMatch>Edit file/etc/httpd/conf.d/welcome.confand comment everything. Simply removing thewelcome.conffile (or renaming it as.conf.disabledfor example) should do the trick too.Then, reload apache configuration (service httpd restart) and things should work as expected. | I have installedzpanelwithcentos 6.3.
Now what is the problem.I have added domainmydomain.comand I have added blankindex.phpfile.
I added too.htaccessfile with "deny from all"
Now when I open the page in the browser, I get Apache 2 Test Page instead403 ForbiddenBut if I openhttp://mydomain.com/index.php, now I get 403 Forbidden.I tried to edit the apache config fileDirectoryindexbut there is no positive result. Anyone can help me? | htaccess deny from all gets apache server test page |
Try:RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
RewriteRule ^/?$ /member.php?username=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
RewriteRule ^/?contact$ /contact.php?username=%1 [L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
RewriteRule ^/?album/([a-zA-Z0-9_-]+)/([0-9]+)$ /album.php?username=%1&title=$1&album_id=$2 [L] | Currently, I'm having an url system like this by using the htaccess:- www.domain.com/member/username
- www.domain.com/member/username/contact
- www.domain.com/member/user/album/title-of-the-album/albumID.. something like thatHere is my htaccess, and it worked perfectly.RewriteRule ^member/([a-zA-Z0-9_-]+)$ member.php?username=$1
RewriteRule ^member/([a-zA-Z0-9_-]+)/contact$ contact.php?username=$1
RewriteRule ^member/([a-zA-Z0-9_-]+)/album/([a-zA-Z0-9_-]+)/([0-9]+)$ album.php?username=$1&title=$2&album_id=$3Now I want to setup a dynamic subdomain system for the user, likes "username.domain.com"
So I decided to used the below htaccess:RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
RewriteRule ^(.*)$ www.domain.com/member/%1 [L]But this redirect the user to their old domain "www.domain.com/member/username" instead of "www.domain.com/member/username"
I want to keep the user stay in "username.domain.com" (no url change in the address bar).If possible, is there any chance to keep the same structure for other new url, such as when I type:"username.domain.com/contact" will load the content of "www.domain.com/member/username/contact" (no url change in the address bar)"username.domain.com/album/title-of-the-album/albumID" will load the content of "www.domain.com/member/username/album/title-of-the-album/albumID" (no url change in the address bar)Please help !! | Dynamic subdomain with htaccess (not redirect) |
I got it working.RewriteEngine on
RewriteCond %{HTTP:X-FORWARDED-FOR} !^127\.0\.0\.
RewriteRule ^(user|admin) - [F] | I just wondering if there's a way to restrict a URL path by certain IP range using .htaccess.Please note that yes this is possible in vhost config, I just wanna know if anyone have tried it in htaccess.. | Restrict URL by IP range in .htaccess? |
You need to add aRewriteBase. When your rewrite rule's target doesn't start with a leading slash (making it an absolute URI), apache needs to guess whether it's a URI-path or a file-path, and it is incorrectly guessing that it's a file-path. Adding a base tells apache that it's a URI path.RewriteBase /or add a leading slash to your target:/company/?alias=$1You also want to add a trailing slash to company and use the[L]flag:RewriteRule ^company/([^/]+) company/?alias=$1 [L,NC]The missing trailing slash may be the culprit that's causing mod_dir andDirectorySlashredirecting. And theLflag may be why the joomla rules are eventually getting applied. | I'm trying to make a rewrite of a url on my joomla site. I have an extra page in there wiht some other stuff on it.I have:RewriteRule ^company/([^/]+) company?alias=$1 [NC]where i want company/somecompany to show what the url company?alias=somecompany will give (not forward to it).What i get instead is a redirection to:http://www.mydomain.dk/var/www/clients/client2/web5/web/company?alias=somecompanyAlso if i include a "-" like "company/some-company" it skips my rewrite and just goes to the joomla rewrite rules (and can't find the article)What am I doing wrong? | My url rewrite redirects to mydomain.com/var/www/clients/client3/web25/ |
It looks like you're delivering those as typeapplication/octet-stream. You'll want to start, then, by delivering them asapplication/pdf. Add this to your .htaccess (if you don't have access to you Apache config or can't reload your Apache config):AddType application/pdf .pdf | I have integrated the following pageclick hereinto expression engine. Only certain PDFs will download in chrome, as demonstrated in the link above, whereas with Firefox users are able to download all PDFs on the page. I've been searching through various expression engine forums and followed instruction such as disabling my XSS Filter and re uploading all my PDFs. I'm also running this latest version of EE and i've tried downloading PDFs logged out of the super-admin account.I'm not sure whether this is a browser issue or an issue with expression engine, has anyone come across this problem before? | PDF not downloading in Chrome |
I would verify public/index.php exists, and then try adding this line to your .htaccess file.DirectoryIndex index.phpYou may also want to tag this with "mamp". Hope you find it! | Coming from CodeIgniter, I'd like to learn Laravel.
But I'm breaking my head 2 days over a (small) problem.When I browse to the URL "laravel.app", It shows me the folder content instead of the index-page of Laravel.These are my settings:Virtual Host:<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/laravel/public"
ServerName laravel.app
<Directory "/Applications/MAMP/htdocs/laravel/public">
Options All
AllowOverride All
</Directory>
</VirtualHost>.htaccess:<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
Order allow,deny
Allow from all
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>I added "Order allow, deny" and "Allow from all", else I get a 404.
What could be the problem?Regards | How to run Laravel app when hosted through virtual host? |
Some clarification: when you do anecho "<img src='....'>";PHP access doesn't matter (in fact it will work even if PHP doesn't have access to the file!). The first step is to realise, that it's the browser that makes the request for the image. So if the browser can access it, the user can access other images by guessing the name of the image. This would even work if you serve the images with readfile from PHP. That's why I wrote that you're trying to solve the problem the wrong way.What youcando, is to obfuscate the image names (or the request variable you send to your PHP script). Eg: use a salt + MD5. That way users cannot guess the names. | I run a web app where I store the users' uploaded files in a folder structure like:www.mydomain.com/uploads/topsecret/1/001.jpg
www.mydomain.com/uploads/topsecret/1/002.jpgNow, it's very easy to guess the urls for 003.jpg and 004.jpg ...Therefore, I want to restrict user access to only www.mydomain.com/app/, and nothing else.
Only my .php pages on localhost should be allowed to get to the top secret pdfs, likeshow.php:
<? if ($isAdmin) {
echo "<img src='http://www.mydomain.com/uploads/topsecret/1/001.jpg'/>";
} ?>Maybe there is a solution via .htaccess or via folder permissions. I know I could fix the problem via "headers" and "readfile", but that would cause a bit of refactoring now.Thank you in advance,
Matthias | only allow PHP scripts to open urls like www.mydomain.com/topsecret/1/001.jpg |
RewriteRule ^(.+)$ index.php?url=$1 [QSA, L]Changed to:RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]Note, "[QSA, L]" vs. [QSA,L]Duplicated your error, removed space, worked). I'm using WAMP. | i'm beginner to MVC framework. I'm trying to create one my own based on tutorials..htaccess file that they provide contains:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA, L]i get 500 server error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.I checked httpd.conf to check if mode_rewrite was not commented. Can anyone help me please? i'm using LAMPP on Ubuntu 12.04 | .htaccess gives 500 error on localhost |
Try these rules in the htaccess file in your document root.RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} ^(/wp-login|/products-page/checkout|/products-page/your-account)
RewriteRule ^(.*)$ https://mydomain.com/$1 [R,L]The first condition checks if the request isn't HTTPS, the second checks if the request starts with either/wp-login,/products-page/checkout, or/products-page/your-account, and if both apply, then the rewrite simply takes the entire URI and redirects to https://. | I've used different codes provided here on other questions' solutions and on the internet. I'm really not savvy withhtaccess. Bought and confirmed working SSL Certificate, but I'm new to applying these redirects.Goal:I need to rewrite http to https on the following directories.http://mydomain.com/products-page/checkouthttp://mydomain.com/products-page/your-accounthttp://mydomain.com/wp-loginI'm on shared hosting via Dreamhost. I have a dedicated IP, if that helps.Initial code I was using recommended to me by a Dreamhost representative:RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} wp-login
RewriteRule ^(.*)$ https://mydomain.com/wp-login/$1 [R,L] | .htaccess url rewrite for ssl https redirection |
You can set restrictions like this:Order Deny, Allow
Deny from all #everyone will not be allowed except the following line
Allow from 127.0.0.1 123.123.123.123 #allowed hosts separated by space | This question already has answers here:Closed11 years ago.Possible Duplicate:Hotlinking my Cascading Style SheetsThis is a bit of a follow up to this question.htaccess don't allow user to view my folder files that don't have index.phpwhich worked perfectly for blocking directory level access, but it still doesn't block direct access if someone knew the urli.e. domain.com/css/ is forbidden, but domain.com/css/main.css shows the css filehow would i block direct access to that file? it seems like such a standard thing but i can't find anything for it | htaccess - can block directory view, but files are still directly viewable [duplicate] |
As others have said, make sure that AllowOverride is set to All in your apache config or your virtual host file.
Given the path that you have codeigniter setup in, your htaccess should look like this:RewriteEngine On
RewriteBase /path/learn_ci
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /path/learn_ci/index.php/$1 [L]Also, remember that any assets you are using (img, css, js, etc) are referenced either with thebase_url()function or using relative paths. The root of your project is going to be /path/learn_ci.I find that it is easier to create a virtual host and add an entry to my hosts file locally. This mimics real life much better. | I am a newbie at codeigniter. I have my codeigniter installed at localhost/path/learn_ci.I have followed all the steps given in the codeigniter wiki. Here is my .htaccess file.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /learn_ci/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>I've also changed the config file as required. But when I try to accessI get this error"The requested URL /learn_ci/index.php/welcome was not found on this server"I have double checked...the mod_rewrite module in Apache is on.The RewriteBase solution also didn't work. Am I doing something wrong?? | Remove index.php from codeigniter url |
Change your rewrite rule to this:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ index.php?id=$1 [L,QSA]Key change is use ofQSAflag which will preserve original query string even after addingid=$1. | How can I take the page var fromhttp://domain.com/recent?page=2(the original page ishttp://domain.com/?id=recent&page=2) with .htaccess? (i need a general rule for all pages) thanx for help | .htaccess General Rule for all Pagination |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.