Response
stringlengths
8
2k
Instruction
stringlengths
18
2k
Prompt
stringlengths
14
160
In order to match specific query string youhaveto usemod_rewrite. Please check if it is installed/allowed on your host. The rule in this case will be something like this:# most likely be required for rewrite rules to function properly Options +FollowSymLinks +SymLinksIfOwnerMatch # Activate Rewrite Engine RewriteEngine On RewriteBase / # actual rule RewriteCond %{QUERY_STRING} ^action=this&id=1 [NC] RewriteRule ^index\.php$ /index.php?action=this&id=2 [R=301,L]This needs to be placed in .htaccess in website root folder. If placed anywhere else some small changes may be required.This rule will only redirect/index.php?action=this&id=1to/index.php?action=this&id=2and no other URLs (just as you asked in your question).
I want to redirect index.php?action=this&id=1 to index.php?action=this&id=2I tried the code below in my .htaccess but it didn't helpredirect 301 index.php?action=this&id=1 http://mysite.com/index.php?action=this&id=2What am i doing wrong here? what could be a workaround?
htaccess redirect not working with URLs with parameters
Do you want any/forum/footo be/foo? If yes then use this code in your .htaccess:Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^forum/(.+)$ $1 [L,NC,R]
how to change url for examplehttp://mysite.com/forum/forum.php?id=1ahttp://forum.mysite.com/forum.php?id=1
hide some middle part of URL
try adding the following to your .htaccess fileRewriteEngine on #Home: Exclude the home Page RewriteCond %{REQUEST_URI} !^/$ [OR] #News: exclude anything that starts with /news, /products etc RewriteCond %{REQUEST_URI} !^/(news|products|offers|our-philosophy|our-team|our-dream) [NC] RewriteRule (.*) http://www.cotswold-fayre.co.uk/$1 [R=301,L]
I'm currently moving a site (shop) to a new domain and putting in its place a non-shop version (made in wordpress) of the site. The aim is for most of the urls to redirect to the new domain except the few pages that the new site has. I've found other posts on stackoverflow but unfortunately I can't seem to get it working. Any help would be much appreciated, Thanks Jason.The urls I need to exclude are: / (Homepage) /news and its posts /news/post-name /products and its posts /products/post-name /offers and its posts /offers/post-name /our-philosophy /our-team /our-dreamHere's what I tried:<IfModule mod_rewrite.c> RewriteEngine on #Home RewriteCond %{REQUEST_URI} !^/ #News RewriteCond %{REQUEST_URI} !^/news(.*) #Products RewriteCond %{REQUEST_URI} !^/products(.*) #Offers RewriteCond %{REQUEST_URI} !^/offers(.*) #Philosophy RewriteCond %{REQUEST_URI} !^/our-philosophy(.*) #Team RewriteCond %{REQUEST_URI} !^/our-team(.*) #Dream RewriteCond %{REQUEST_URI} !^/our-dream(.*) RewriteRule (.*) http://www.cotswold-fayre.co.uk/$1 [R=301,L] </IfModule> # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
301 Redirects (htaccess) with exclude conditions
I figured it out, though I'm not sure why this works:I switched the rules around so they happened in reverse order. Code that works is as follows:RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$ RewriteRule !(specialexception)+\.php)$ /path/to/index.php [NC,L]The problem with this solution:Since "specialexception.php" is listed as the last rule, in the actual RewriteRule line, it only solves the problem for ONE file exception.One messy way around this might be to use the pipe in the last line of regex:RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$ RewriteRule !(specialexception|anotherexception|foo|bar)+\.php)$ /path/to/index.php [NC,L]If anyone has a better idea on how to add multiple exceptions for multiple files, I'd love to know!
I use .htaccess Mod Rewrite to send the URL to index.php, which then parses the URL and builds each page of my website. This works perfectly fine, allowing me to easily manage clean URLs using PHP instead of .htaccess.Ex:http://domain.com/some/url/here/-> goes to index.php, which loads a page with multiple PHP files put togetherHowever, I'm trying to allow certain PHP files to load as regular PHP files (without sending the URL to index.php to parse).Ex:http://domain.com/some/url/here/still works as mentioned above.http://domain.com/specialexception.phpwill load as a regular php file, without sending to index.phpI have the following code:<IfModule mod_rewrite.c> RewriteEngine On RewriteCond $1 !^specialexception\.php$ [NC] RewriteRule !\.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$ /path/to/index.php [NC,L] </IfModule>However, the RewriteCond line is simply ignored right now.I would appreciate any help/ideas!Thank you.
htaccess RewriteCond, Multiple Conditions for RewriteRule
I have never done this before, but this shows how to do it:http://www.webmasterworld.com/apache/3589651.htmvia .htaccess.Edit: Maybethis(snapshot) shows exactly what you want, it's a walk-through of how to embed header and footer in the listing page.
You know how when you go to a url on a server and the directory doesn't have an index.* file or a default.* file it shows you a list of the directorie's contents? I was wondering if there is any way to customize the way that index looks or theme it to fit your site. For instance I'd want to add the php<? include 'template.php'; head(); ?>Before the listing. And<?php foot(); ?>After. Can this be done?
Is it possible to use .htaccess to make custom Index Of pages? If so how?
For your specific example, you'll want to create a route (inapplication/config/routes.php) that maps$route['mission/']to"content/index/mission"In other words,$route['mission/'] = "content/index/mission";See theCI documentation regarding URI routingfor more info
I am having a serious issue with one application developed in CI. Currently my URLs look like thishttp://www.example.com/content/index/mission/I want to remove /content/index/ from URL So, It should look something like this.http://www.example.com/missionI have routing and .htaccess method as well. But nothing seems to be working.Here is my .htaccess fileOptions +FollowSymLinks RewriteEngine on RewriteBase / RewriteCond $1 !^(index\.php|images|css/js/style/system/feature_tab/robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [QSA,L]I have also tried routing of CI by defining reouters in config/router.php But it was not working :(
How to remove Controller and function name from URL in CodeIgniter
RemoveHandler .suffixwhere.suffixis the filename suffix for the type of a script you want to disable should do it.Looking for something that disallows scripts in general right now.Edit: Aha! If you don't mind having to serve everything in the directory as static content — you probably don't, that's what your question seems to imply — you could just set the default handler for that location.<Directory something> SetHandler default-handler </Directory>default-handler is in core so this shouldn't depend on anything. Correct me if I'm wrong.
I would like to disable any kind of CGI execution in a directory below my document root directory. Any kind: php, perl, ruby... whatever. I would like to do it in a manner it's not depensant of the file extension. Below my document root because users have to be able to put and see HTML files.It has to be in htaccess, because it's a shared hosting.Using -ExecCGI alone is not working. I have to add to that line a AddHandler directive which is extension dependant.I have foundsome close answer in this topic, but they are extension dependant, php dependant or global apache configuration dependant.Is it possibly to do what I want?Thank you very much,
How to disable cgi in htaccess in a non-extension dependant way?
Apache has two ways of storing configuration options:The central configuration (the .conf files) - when you change these, you need to restart the server..htaccessfiles whose settings apply only to its directory, and all child directories. Changing these does not require a server restartIf you're on a dedicated server, youcouldtheoretically migrate all.htaccessfiles into the central configuration, but WordPress will write into a.htaccessfile when updating its permalink structure, so you'll always have at least that.In my experience, keeping individual.htaccessfiles is relatively practical in everyday maintenance work as long as they're nottoomany. I would leave things as they are.
I'm looking through my server because I want to restrict access to some specific folders and i've noticed I have several .htaccess files. One is in the root, the directory before public_html, is that the root, or is public_html the root? And that file enables php5 as default. I then have a htaccess doing some url re-writing in the public_html folder, then I have another one in the wordpress directory.Is there a need for them to be spread out?Do I have one htaccess for each folder I want affected or does the htaccess affect a folder plus all of the sub directories?ThanksEdit: Also have another htaccess in my wordpress theme folder?
Why do I have .htaccess files in multiple directories?
Add aDefaultType text/xml(or whatever type you're using for your XML) to your.htaccess.
I have a XML page www.example.com/page, but my server outputs it as text/plain as it doesn't have any extension.So I want to add XML Header via .htaccess to all the files which doesn't have extension with a condition that thefile exists. As if file doesn't exist, program is executed from database and it decides what header to output, so I don't want to break that part by forcibly changing header.
How to add Header Content-type to static pages which doesn't have extensions?
You need to create the rule such where all requests are directed to a external script. Then the server script may look up the database, set cookies and redirect. The .htaccess can not do this by itself unless you write a extension for apache which is likely to be beyond the scope the application you need right now.For now just redirect all requests to a script byRewriteRule ^([A-Za-z0-9-])$ /advert.php?id=$1 [L]you can use$ad_string = $_GET["id"];to get the ad string in the $ad_string variable. Then you can make a connection to the database usingmysql_connect()and then run a sql query like"SELECT * FROM advert_table WHERE id = '" . mysql_real_escape_string($ad_string) . "'"This should sort out your url for the query. then use ameta redirector ajavascript redirector even aheader 301 redirect.
Here is what I want to do:User comes to my site fromwww.mysite.com/advert1(folder advert1 doesn't exist).htaccessthen removeswww.mysite.com/leaving justadvert1Storeadvert1as a string in a cookieLook foradvert1in a database then redirect the user to the URL specified in the database e.gmysite.com/news.Is this possible?
htaccess redirect based on URL stored in database
You can try to identify the country by IP. For example seehttp://www.ip2location.com/This will not cover everybody, but should be ok for most cases.
we have three domains one for US, one for UK, and one for Canada. i want that my users should be automatically redirected to country specific URL no matter what domain they open.e.g. if the user is from US and he is opening example.co.uk then he/she should be redirected to example.com.
How to identify the country & change the URL accordingly
You should in general exclude all real files and directories, as this will handle css/js/images/whatever else you want to serve:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)$ profile.php?username=$1 [L]
I want that every user has a profile-url like this:www.example.com/usernameI have created this htaccess:RewriteEngine on RewriteRule ([^/]+) profile.php?username=$1 [L]but I get error with the css and js files.what I have to write in the htaccess ?
htaccess+modrewrite issue
First thing, your .htaccess should be like this:<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{THE_REQUEST} !^GET\s/+online/ [NC] RewriteRule . /index.php [L] </IfModule> #Then add this for CI handling in the same .htaccess RewriteCond %{REQUEST_FILENAME} !-f RewriteCond $1 !index\.php [NC] RewriteRule ^online/(.*)$ online/index.php?/$1 [L,NC]Then you can remove (or rename) .htaccess in theonlinesubfolder.
The main site runs WordPress with .htaccess<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>I'm going to create an CodeIgniter app in subdirectorysite.com/online/If simply add CI .hta file in subfolder it wouldn't work. CI .htaccess:RewriteEngine on RewriteCond $1 !^(index\.php|robots\.txt|img|styles|js) RewriteRule ^(.*)$ /index.php?/$1 [L]Is it possible to combine two .htaccess files or to do something with .htaccess in CI subfolder? Thank you.UPD.Thank you for answers, I've tried all variants, and eventually moved project to subdomain.
.htaccess in subfolder
Your .htaccess is almost right, just minor corrections:Options +FollowSymlinks -MultiViews RewriteEngine on # for http RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com$ [NC] RewriteCond %{SERVER_PORT} =80 RewriteRule ^(.*)$ http://CurrentDomain.com/$1 [R=301,L] # for https RewriteCond %{HTTP_HOST} ^(www\.)?newdomain\.com$ [NC] RewriteCond %{SERVER_PORT} =443 RewriteRule ^(.*)$ https://CurrentDomain.com/$1 [R=301,L]That waynewdomain.comorwww.newdomain.comwill both be redirected with 301 to the browsers.[NC]flag is for ignore case matching of host
I am much more of a programmer than a server guru so any help is much appreciated!Forwarding a domain name for SEO reasons ->NewDomain.com hosted with 3rd party needs to point to currently hosted site CurrentDomain.com. I know I need to...1) Adjust NewDomain.com DNS A records specificallywww.@.*.ftp.mail.2) Adjust NewDomain.com DNS MX records3) Add 301 Redirect to .htaccess file hosted at CurrentDomain.com so all requests for NewDomain will be forwarded to CurrentDomain.com.RewriteEngine OnRewriteCond %{HTTP_HOST} NewDomain.com$RewriteRule ^(.*)$http://CurrentDomain.com/$1 [R=301,L]THE QUESTIONS:What else needs to be done?1) Is something missing?2) Should additional DNS changes be made? If so, where?3) Should MX record point to mail.CurrentDomain.com if I don't want mail to NewDomain?4) Is there a better .htaccess file?
How to Forward Domain Name to Existing URL - .htaccess, DNS records, what else?
) Make sure you've enabledmod_rewritein the Apache configuration file.2) Add the lineAllowOverride Allto the directory configuration in the Apache config file.Additionally, unless you have a lot of rewrites, I recommend the following over your current rules.SetEnv APPLICATION_ENV development RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-s RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [NC,L]
I have done a fresh installation of xampp , after installing the folder containing followinghtaccessfile is not showing in my browser.SetEnv APPLICATION_ENV development RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]it gives 500 error and the server is overloadedThis happens when I am trying to execute the public folder in my zend application.Please suggest to me whether I have to do any modifications in my xampp for getting my.htaccessfile to execute correctly.Thanks in advance
.htaccess not working
Short answer: NoEthernet MAC is not transferred in a IP packet, only in the Ethernet header. When the IP packet leaves the LAN (technically the local broadcast domain) the Ethernet header is stripped off and the MAC address is "lost".
Is it possible with.htaccessfiles to only allow requests from a specific MAC address instead of an IP address?And if the answer isyes, how?
Allow only specific MAC addresses in Htaccess
You need to have "mod_rewrite" installed in apache. Assuming you do, place a .htaccess file in the root directory of that account (probably:)~/public_html/.htaccessand then put this in that fileRewriteEngine on RewriteCond %{HTTP_HOST} ^website.nl(.*)$ [OR] RewriteCond %{HTTP_HOST} ^www.website.nl(.*)$ RewriteRule ^.*$ "http\:\/\/www\.website\.nl\/holland\/$1" [L,P]And then repeat the rewrite condition for website.deBasically that says, grab the section after the website.nl part, and paste it on the part after holland, but the "L,P" says to make that a silent redirect and keep the user on the same url as they entered with.goodluck!
imagine the root of a server where multiple aliases such as website.nl; website.de; etc. all direct to the root the root \httpdocs\ with this physical hosting:httpdocs\... httpdocs\holland\ # webpages in Dutch (home.php | contact.php | etc) httpdocs\deutsch\ # webpages in English (home.php | contact.php | etc) httpdocs\images\ # all multilingual webpages share the same images httpdocs\js_css\ # all multilingual webpages share the same scripts/layout httpdocs\.htaccess # here be a clean root, nothing else than .htaccessThus, only the webpages .php differ: the rest they all share the same! Now imagine that you want to configure .htacces via apache script to make "bridge the gap" if you will, between the root and the folder, making it possible to type this in browser and below water fetching the right php webpage, but keeping the shorter url in the browser:website.nl/home.php//files fetched should come from the holland folder associated with website.nlwebsite.de/home.php//files fetched should come from the deutsch folder associated with website.de(As opposed to seeing this in the browser: website.nl/holland/home.php | website.de/deutsch/home.php)What apache script line will do such thing?Thanks: Much appreciated!
How to Route Various domain Aliases to Fetch their Own Folders with Own Webpage PHP Files?
This code worked for me:## REWRITE RULES # enable rewrite RewriteEngine On RewriteBase / RewriteRule ^(news|contact)(/?)(.*)$ #/$1$2$3 [R,NC,NE,L]
Basically I'd like to emulate what Hypem.com does with their urls, if you go tohypem.com/popularyou get redirected tohypem.com/#/popularHow can I do this with htaccess? I have several basic urls that I need to redirect, all others stay the same, for example, these two need to redirect:/news/contactBut/adminshouldn't
htaccess rewrite to hash for ajax
Note the extra E. :)RewriteCond %{REQUEST_URI} !/uploads/ RewriteCond %{HTTP_HOST} theDomainThatWillBeRedirect.com RewriteRule (.*) http://theDestinationDomain.com/$1 [L,R=301]
I have a little question very simple this time I think... How Have I to write my htaccess to do this instructions :IF IS "/uploads" PATH INTO MY REQUEST, NOT REDIRECT AT ALL, JUST DO THE REGULAR REQUEST ELSE DO THE REWRITERULE : RewriteRule (.*)http://theDestinationDomain.com/$1 [P,L]I Have tested that :RewriteEngine on RewriteCond %{REQUST_URI} !^/uploads/(.*) RewriteCond %{HTTP_HOST} theDomainThatWillBeRedirect.com RewriteRule (.*) http://theDestinationDomain.com/$1 [P,L]That Just don't work... That make always the redirection to theDestinationDomaine.com/...Any idea ?Thanks a lot !See youOlivier
.htaccess : if is an path, do nothing, else, do the rewriterule
To make url look nice is one thing.To hide url data is another. Never hide anything. Or you will make your site unusable.
I have a url that is constructed using get variables likelocation.href = this.href +'?type='+ escape($('#type_of_station').html()) + '&count='+ escape($('.number_changer').attr("id").slice(-1));which gives me a url like the followinghttp://posnation.com/pre_config/pre_config_step_2.php?type=Grocery&count=2on the following page I grab the variables via PHP<p id="type_of_station" class="text left"><?php $_GET['type'] != "" ? print str_replace("_", " ", $_GET['type']) : print "Food Pos System" ?></p>This works great but the url is kind of ugly. Is there a way to maybe hide this and still have the get variables available to me on the next page
Hiding the get variables
The directly answer your question, the answer isno. By the time, .htaccess is read, the path was already translated to a directory.If you want to change the root, you have to do it inhttpd.conf(or rewrite all the requests in the root to the destination directory). If you want to have several roots (under different domains), you have to use virtual hosts (again, only inhttpd.conf).You can also make your site work when it's not in the root directory.Use relative paths correctly ("../index.php" in "/contact/index.php" and "index.php" in the root webpages). Not a great option.Use absolute paths, but prefix them with the path of the website relative to the server root. The most fool-proof way to do this setting a constant for this in a file that you include in all your scripts.
Is there a way to make .htaccess tell a folder to act as the lowest level? What I mean is this, say you have a folder like so:/about/ /contact/ /css/ /images/ .htaccess index.php header.phpIf they are at/contact/index.php, then if I have<a href="../index.php">Home</a>to go to the home page, it works all fine, but if they are on the actual main page, it will try to go a directory lower.The reason is because Im trying to test sites in sub-folders.
.htaccess make folder act as root?
the best way is to use configure to setallthe scripts to require login.you need to hit 'yes i've read all the docco' button at the top, and then expand the Security sectionin there is a setting called {AuthScripts}. any cgi script listed there will require authentication first - so listallof them.alternatively, you can restrict access to a web or topic using the ACL settings - seehttp://foswiki.org/System/AccessControlSven Foswiki developer and consultant :)
I want to set up an internal foswiki to which only authorized users have access to and can view/edit the contents. One way of doing this is to modify the .htaccess file for the folder and generate as many as authorized users. But that is not very secure, so I don't want to use itIs there any way to do this in Foswiki.
Setting up an internal foswiki (only authorized can view/edit)
+50In yourErrorDocumentstatement, you're giving a URL to a remote page. As a result, Apache sends the user a Location header, and the user goes off on their merry way.Instead, change the URL to an absolute path to a local script that will handle the error:ErrorDocument 500 /500.phpThe script should be launched with a set of environment variables starting with REDIRECT_ that should contain the various paths and query strings involved in the error.There is no way to both send the user elsewhere and also capture the information within ErrorDocument itself. On the other hand, your script can capture the information and then redirect the user, if you still want to handle it that way for some reason.
So, in my .htaccess file I have this ErrorDocument lines:ErrorDocument 500 http://www.example.com/500Since my server runs multiple websites from the same core files, I just want to redirectallinternal server errors to the same processing page. However, my problem is that it doesn't send any information about the page that cause the error, it redirects the page. I tried changing it toErrorDocument 500 index.php?500but that just causes a second internal server error when trying to locate the file. Any ideas on how I can successfully redirect it to my custom 500 error page and still acquire information about the page that caused the error in the first place?
How do you detect what page caused the Internal Server Error?
EDITThere's a simple way to do it. In your .htaccess, addErrorDocument 401 /path/to/log.phpThislog.phpis then called when a login attempt fails (you can put it behind the protected directory as well, it will be reached even though the login fails). Note that the browser doesn't know whether some resource needs authentication, so you'll always get a hit for the first attempt. These attempts, however, will not include any username and you can detect them (well, you can distinguish them from when the user enters no username, but you get the idea) by checking whether$_SERVER['PHP_AUTH_USER']is empty.OriginalWell, no, as you say/index.phpis never reached.What you can do is not to rely on Apache at all and handle the authentication only with PHP. Thismanual pageshows you how. This has a big disadvantage. Let's say you protected an entire directory. This directory has PHP files, images and whatnot. Now, to enforce the authentication, you must route everything through a PHP file. If you had only PHP files, you could do it with an include. If you have static contented, you must route it with a rewrite-rule through a PHP files that reads and outputs the static content, which will hurt the performance.
This question is related to aprevious questionI asked, but it's a different.I'm using htaccess to control login tohttp://somesite.com/folder.Once logged in, I have php code infolder/index.phpto check the username and password used to login:$_SERVER['PHP_AUTH_USER']and$_SERVER['PHP_AUTH_PW']. I log that info to a database.This works when the user supplies a good username and password, but when it's incorrect, nothing happens - I suppose because/index.phpis never reached.Is there a way to login also failed login attempts?
How about failed attempts for htaccess password protected directories
mod_rewritecan strip off the query string:RewriteEngine on RewriteRule ^/?oldfile.php$ http://www.site.com/show/newurl? [R=301,L]
For a website I'm currently working on we're redirecting our old URL's permanently to new ones like this: Redirect 301 /oldfile.phphttp://www.site.com/show/newurlNow I come across this situation in which the old url has a get var like: Redirect 301 /oldfile.php?var=namehttp://www.site.com/show/newurlThis will redirect the oldfile to the new url plus it adds the get var so it redirects to:http://www.site.com/show/newurl?var=nameHow would I set up this redirect without the get var?
.htaccess 301 redirect without GET var
The problem was being caused by the/etc/httpd/conf.d/welcome.conffile:Options -Indexes ErrorDocument 403 /error/noindex.htmlThat file overrides the htaccess and turns indexing off for any root web directory.Renaming it to welcome.conand restarting the server solved the problem.
I need to offer adirectory listing of the root directoryof my site, so I created an.htaccessfile containingoptions +indexesIt works for subdirectories, but for the main directory I get theTest Page for the Apache HTTP Server on Red Hat Enterprise Linuxpage.I have two sites that are identical except for thePHP versioninstalled. On one site (PHP 5.2.1) this technique works fine. On the other (PHP 5.2.9), it doesn't.As far as I know, theApacheinstallations are identical, and I verified that thehttpd.conf files are identical.On both sites, the htaccess works for subdirectories. My problem is with the main site directory.My goal is to create simple sites based on directory listings, similar toznvy.com.Is there something about the updated PHP version thatprevents listing a root directory? If so is there aworkaround?[update]I looked at the page usingrex swain's http viewerand the server of the problem site is returning a 403 status with the Apache default page.
PHP/Apache, options +indexes in htaccess doesn't work for root directory
I doubt there's a better way than listing out the 90 pages manually in your.htaccess:redirect 301 /somedeletedpage.htm http://www.example.com/unless the 90 removed pages have some common characteristics that can be regexed.
I have cleaned up my site and discarded lots of pages. I have now 10pages left of a 100page site, all static html. I want any request for deleted pages to 301 redirect to homepage but can't figure out the .htaccess rules!
.htaccess 301 redirect to homepage if page not found
That you need to do this in the first place is kind of a failure of project architecture. Script files that shouldn't ever be accessible to the Web shouldn't be inside your DocumentRoot in the first place.That said, this will probably work:RewriteEngine on <DirectoryMatch "/(?!.*/ajax$)"> Order deny,allow Deny from all </DirectoryMatch>
I have this .htaccess file where I prevent users from physically accessing files from the browser (where they should only be loaded through the system)Options -Indexes Order deny,allow deny from allI have one problem though, sometimes I load files via AJAX and there I get 403 Forbidden. I have little experience with apache's mod_access. I've been reading up on thedirectory directivesince all my AJAX based files are in one directory called ajax.But the thing is I need to deny access to all directories except ones called ajax and my regex skills are lacking.An example directory structure is like this.plugins/inventory/ajax plugins/inventory/controller plugins/inventory/view plugins/packages/ajax plugins/packages/controller plugins/packages/viewThe .htaccess file sits in the plugins directory.
How can I deny all but one directory name with .htaccess?
Try this rule to redirect requests for.phpfiles:RewriteCond %{THE_REQUEST} ^GET\ /(([^/?]*/)*[^/?]+)\.php RewriteRule ^.+\.php$ /%1 [L,R=301]
I am currently using the following rules in a .htaccess file:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.phpThis works well to ensure that/myfile.phpworks as well as justmyfile(with no extension in the URL). It also handles querystrings with no problems, somyfile?var=fooalso works.The problem is that these are registering in Google Analytics as being two separate files. So whilemyfile.phpmight be the third most popular page on my site, with X visits,myfilemight be the fifth most popular page on my site with Y visits.How can I do a hard redirect, rather than "accept either one" type of rule?
URL Rewriting - Redirect With No File Extension
In first time, don't forget to enable the rewriting ("RewriteEngine on"). The last line is important if you use Zend Framework.RewriteEngine on RewriteCond %{HTTP_HOST} ^mysite.com [NC] RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301] RewriteRule !\.(pdf|php|js|ico|txt|gif|jpg|png|css|rss|zip|tar\.gz)$ index.phpNow the url...http://mysite.com/some-file.htm... redirect tohttp://www.mysite.com/some-file.htmbut use the index.php
I want to force a www. prefix on my website by using a .htaccess 301 redirect. I am currently trying:RewriteCond %{HTTP_HOST} ^mysite.com [NC] RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]Which normally works, but I am using Zend Framework which causes all requests to be redirected back tohttp://www.mysite.com/index.phpregardless of the initial request.For example...http://mysite.com/blog, http://mysite.com/contact, http://mysite.com/blog/this-is-my-article,Will all be redirected tohttp://www.mysite.com/index.phpHowever, if I initially request a specific file, such as...http://mysite.com/some-file.htmThe redirect works properly, redirecting tohttp://www.mysite.com/some-file.htm
How do I use .htaccess to force www. while using Zend Framework
You could use a script as arewrite mapto get the real path.
I would like mod_rewrite in an .htaccess file to link to a mysql database to provide me with mapping information.Specifically, I am using a single code base to host multiple sites so..if a user requests an image, for example:http://www.example.com/images/car.jpgthis is going to hit my server and many other sites will also be hitting that /images folder, so I need Apache to reply with: /home/example/pubic_html/images/7383/car.jpgNotice the injection of "7383" which is an example site id for that user.Basically, I want to map between example.com and 7383 using the mysql database and then get the correct file to the user.Any ideas?
mod_rewrite, .htaccess connecting to mysql database
Have it this way in your .htaccess:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^(.*/)([^/]+/?)$ RewriteRule ^ %1#%2 [L,NE,R=301]A note aboutRewriteCond %{REQUEST_URI} ^(.*/)([^/]+/?)$:We are using 2 capture groups in regex here:(.*/): Match longest match before last/being represented as%1later([^/]+/?): Match last component of URI being represented as%2laterIn target we use%1#%2to place a#between 2 back references.
I am attempting to rewrite the URL on my website using the .htaccess but have had no luck so far. I want to add a hash to the URL and redirect.I want to get the last file in the URL and redirect it to the same URL but append a # symbol before the last file. The reason I want to do this is for my website, all the content is loaded dynamically without refreshing the page.For example,www.example.com/foowould becomewww.example.com/#fooorwww.example.com/form/bar.phpwould becomewww.example.com/form/#bar.phpI don't mind if I need one entry for each page, I have tried many variations but nothing has worked so far.RewriteRule ^(.*)foo(.*)$ $1#foo$2 [R=301,L] RewriteRule ^(.*)/(.*)$ /$1#$2 [L,R=301,NE]
Adding a # symbol and redirecting to a url using htaccess
UseRedirectMatch, which matches using a regex, rather than simple prefix-matching (as withRedirect) to redirect requests for the folder only.For example:RedirectMatch 301 ^/myfolder/$ https://www.example.com/mypage.htmlBothRedirectandRedirectMatchbelong to the same Apache module: mod_aliasYou will need to clear your browser cache if you have been experimenting with 301 (permanent) redirects. Test first with 302 (temporary) redirects to avoid potential caching issues.
I'm struggling with a fairly simple 301 redirect.I have several redirects for pages which all work fine - egRedirect 301 /folder/mypage1.html https://www.example.com/folder/mypage2.html.However now I want to redirect from a folder root to another page, I don't however want any of the other pages in the folder to redirect.So/myfolder/should redirect tohttps://www.example.com/mypage.htmlbut/myfolder/mypage.htmlshould not redirect.I've tried:Redirect 301 /myfolder/ https://www.example.com/mypage.htmlbut this doesn't work.I apologize for the newbie question that probably has a very simple answer.
301 redirect folder root
With your shown attempts, please try following htaccess rules file. Make sure to clear your browser cache before testing your URLs. New rules are clubbed to your already existing rules.RewriteEngine ON RewriteBase /site/ ##New rules from here...... RewriteCond %{THE_REQUEST} \s/site/?\?page=([^&]*)&place=([^&]*)\s [NC] RewriteRule ^ /site/%1/%2? [R=301,L] # Internally rewrite new path to the original one RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^site/([^/]*)/(.*)/?$ index.php?page=$1&location=$2 [NC,QSA,L]
I am trying to see how I can achieve the following rewrite rules.Fromhttps://localhost/site/?page=place&place=west https://localhost/site/?page=location&location=citynameTohttps://localhost/site/place/west https://localhost/site/location/cityI am able to change https://localhost/site/?page=place to https://localhost/site/place but not with another additional query as mentioned above.htaccessRewriteEngine On #Redirect /site/?page=foobar to /site/foobar RewriteCond %{THE_REQUEST} /site/(?:index\.php)?\?page=(.+)\sHTTP [NC] RewriteRule ^ /site/%1? [L,R] # Internally rewrite new path to the original one RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?:site/)?(.+)/?$ /site/?page=$1 [L,QSA]The above htaccess works for the following which is what I also need.https://localhost/site/place https://localhost/site/about https://localhost/site/contact
URL Rewrite - Multiple query
Most of the code in.htaccessshould be the same on local and production. (Otherwise, how do you test it?)However, one of the cleanest ways to separate directives between servers is toDefine(requires Apache 2.4) a variable in the server config of one of the servers (eg. the development machine):Define DEVELOPMENTThis can be defined anywhere in the server config (not.htaccess), but is always seen asglobalto the server, regardless of whether it is defined inside a<VirtualHost>container or not. You do not need to specify avalue(2nd) argument since the<IfDefine>directive (see below) does not check this. As always, whenever you make changes to the sever config you'll need to restart Apache for the changes to take effect.And reference this in.htaccess:<IfDefine DEVELOPMENT> # Local / development directives only </IfDefine> <IfDefine !DEVELOPMENT> # Live / production directives only </IfDefine>The!prefix tests that the variable isnotdefined.Depending on what type of directives you need to contain you can use an<If>container and check something like the requested hostname (eg.staging.example.comvswww.example.comfor the live site). However,<If>containers do not work the same with mod_rewrite.Reference:https://httpd.apache.org/docs/current/mod/core.html#define
How to create an Htaccess which will have a specific and separate code for Localhost and Production. I mean when we work on localhost, it should be work localhost code and in Production it should be load only Production code. So that i can use one Htaccess for Local and Production and it will save lot of time. Following is the model i would like to implement. It would be much appreciate anyone can help on this. Because i spend lot of time on it and not found any good approach on this. Thanks in Advance!<Localhost> ---localhost code goes here ---it should be only work in localhost and not at all in Production </localhost> <Production> ---production code goes here ---it should be only work in Production and not at all in Localhost </Producton>
Htaccess separate for Localhost and Production
With your shown samples, please try following htaccess rules file. Place your https and www implementing rules at top of your file.Make sure your htaccess and index.php files are in root directory. Please make sure to clear your browser cache before testing your URLs.RewriteEngine On # Redirect from HTTP to HTTPS RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^test/?$ index.php [NC,L]Change the structure of htaccess as follows with your shown samples apart from few minor other changes in htaccess(like fixed regex for redirection, usedNEflag in redirection, combined Rules for https and www redirects etc; to improve your rules file)| .htaccess | www | -- index.php | -- .htaccess (new)
When trying to create URL rewrite rules on my server, I ran into some problems so wanted to test if it was working at all with a more simple case: The URLexample.com/testshould be rewritten asexample.com/index.php, a real page that exists on my site.Here is the full content of my.htaccessfile:AcceptPathInfo Off SetEnv PHP_VER 5_3 SetEnv REGISTER_GLOBALS 0 RewriteEngine On RewriteRule test.php index.phpAnd the result when I enter the URLexample.com/test.php:404 Not Found: The requested URL was not found on this server.I made the.htaccessdocument slightly more simple for this test than it usually is. Usually, I also have the following rules in the document:# Redirect from non-www to www RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] # Redirect from HTTP to HTTPS RewriteEngine On RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]These rules have always worked as they should. Is there something wrong with my test rewrite rule, and if not, why are the rewrite rules working for www and HTTPS redirection?This is the structure of the files on my server:| .htaccess | www | -- index.php
Simple rewrite rule is not working on Apache server
With your shown samples/attempts, please try following. Please make sure to clear your browser cache before testing your URLs.Options +FollowSymLinks -MultiViews RewriteEngine ON RewriteCond %{THE_REQUEST} \s/(top_admin/order)\.php\?do=([^&]*)&oid=(\d+)\s [NC] ##Rule for external rewrite with 301. RewriteRule ^ /%1/%2/%3? [R=301,L] ##Rule for internal rewrite to .php file. RewriteRule ^([^/]*)/([^/]*)/(.*)/?$ $1.php?do=$2&oid=$3 [L]
I have URLs likehttp://url.com/top_admin/order.php?do=view&oid=124and I need to rewrite it tohttp://url.com/top_admin/order/view/124, where top_admin is a folder that contains my script. this is my code:Options +FollowSymLinks RewriteEngine on RewriteRule ^order/(.*)/([0-9]+) order.php?do=$1&oid=$2 [L]but it does not work.
How could I rewrite urls properly?
With your shown samples, please try following. Please keep your .htaccess file inside your root folder.Please make sure to clear your browser cache before testing your URLs.RewriteEngine ON RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^word/(.*)$ word.php?word=$1 [QSA,NC,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^en/word/(.*)$ en/word.php?word=$1 [QSA,NC,L]
I am trying to rewrite different URLs. The first three lines work, but lower ones do not. I get a 500 Internal Server Error. A snippet of my htaccess file:RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^word/(.*)$ word.php?word=$1 [QSA] RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^/en/word/(.*)$ /en/word.php?word=$1 [QSA]It would be very nice if someone could help me, as I can't find a solution. What am I doing wrong?Greetings, Andreas
Rewriting mulitple URLS
With your shown samples, could you please try following. Since you are using very generic regex(not giving any uri condition in it) so its not reaching to your last rule of blog page. Keep it as your first rule like as follows. I have also fixed your regex in your all existing rules.Please make sure to clear your browser cache before testing your URLs.###Making Rewriteengine ON here. RewriteEngine ON ##Placing rule for URIs starting from blog here. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^blog blog.php [NC,L] ##Placing rule for url like: http://localhost:80/test1/test2/test3 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?:[^/]*)/(?:[^/]*)/(?:.*)/?$ product.php [L] ##Placing rule for url like: http://localhost:80/test1/test2 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?:[^/]*)/(?:.*)/?$ results.php [L] ##Placing rule for url like: http://localhost:80/test1 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ results.php [L] ErrorDocument 404 http://www.example.com/404.php
I want to redirect this URLhttp://www.example.com/blog/Title-hereto myblog.phppagePlease noteTitle-herecan be anything.How I can do that ?I am trying following but it's not working.RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^blog/(.*)/?$ blog.php [NC,L]I don't know why.Following is my full .htaccess code, may be here's the issue.RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/(.*)/(.*)/?$ product.php [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/(.*)/?$ results.php [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/?$ results.php [NC,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^blog/(.*)/?$ blog.php [NC,L] ErrorDocument 404 http://www.example.com/404.php
Redirect Rule in .htaccess php
If you don't want to change the URL then simply remove the redirect flag from yourRewriteRule.Do the following :ChangeRewriteRule ^(.*)$ /HTML/pages/construction.html [R=302,L]ToRewriteRule ^(.*)$ /HTML/pages/construction.html [L]
I have a .htaccess file and i've set up a 'Coming Soon' website. It excludes my ip as i'm the developer but for other visitors I don't wan't it to change the url of the address.Here's the file:Options +FollowSymlinks RewriteEngine on RewriteCond %{REMOTE_ADDR} !^12.345.67.89$ RewriteCond %{REQUEST_URI} !/HTML/pages/construction.html RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|css|ico|mp4) [NC] RewriteRule ^(.*)$ /HTML/pages/construction.html [R=302,L] ErrorDocument 404 /HTML/error-pages/404.htmlHow can I do this? Help is very much appreciated
How to keep website url the same in .htaccess 503 redirect
Very nice efforts first of all, could you please try following; written based on your shown samples. Please clear your browser cache before testing your URLs.Also please your .htaccess file just one level abovesurveyfolder.RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /survey/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ https://%{HTTP_HOST}/portal [R=301] RewriteRule ^ survey/index.php [L]
I have a wordpress website in project and I want to mask the URL of all the pages so that when accessing them:https://myweb.com/survey/page1https://myweb.com/survey/page2....is displayed as:https://myweb.com/survey/portalI have this on .htaccess but it doesn't work:RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase /survey/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /survey/index.php [L] RewriteRule ^survey/?$ /survey/portal/Thank you all for your time.
Mask URL rewrite in htaccess
Another regex variant:RewriteEngine On RewriteRule ^a/\d{2}[^7\D]\d{3}/?$ sixdigits.php [L] RewriteRule ^b/\d{2}[^7\D]\d/?$ fourdigits.php [L][^7\D]will match any digit except7
I was trying to get URLs edited in Apache as described below however I have not been successful.If the URI starts with letter 'a' and third digit is not '7' with total digits are 6 then urlhttp://example.com/a/123456/should be rewritten tohttp://example.com/sixdigits.phpIf the URI starts with letter 'b' and third digit is not '7' with total digits are 4 then urlhttp://example.com/b/1234/should be rewritten tohttp://example.com/fourdigits.phpHere is what I have tried with the .htaccess file.RewriteRule ^a/[0-9]+/$ sixdigits.php RewriteRule ^b/[0-9]+/$ fourdigits.php
How to rewrite URL according to a condition?
# To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ $1.php [L]You are getting a rewrite-loop (500 error) because the filename you are checking, ie.%{REQUEST_FILENAME}.phpisn't necessarily the same as the file you are rewriting to, ie.$1.php.If you request/dir/file/filethen theREQUEST_FILENAMEserver variable is<document-root>/dir/file(no path-info), whereas the captured backreference$1is/dir/file/file.Try the following instead:# To internally forward /dir/foo to /dir/foo.php RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^(.*?)/?$ $1.php [L]A request for/dir/file/filewill now fail with a 404, since it is checking that/dir/file/file.phpexists.You don't really need to check that the request does not map to a directory before checking that it does map to a file (twice the work), unless you also have directories of the same name and you need the directory to take priority (unlikely).See alsomy answerto the following ServerFault question that goes into more detail:https://serverfault.com/questions/989333/using-apache-rewrite-rules-in-htaccess-to-remove-html-causing-a-500-error
When I am trying to give url ashttps://example.com/dir/file/filethen the request is getting into loop and 500 error comes while it should give file does not exists. I am using LAMP Stack. I am hiding .php in my .htaccess## hide .php extension # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R=302,L] # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*?)/?$ $1.php [L]
I am getting 500 internal error when giving url as dir/file/file
You can indeed! You need to include a Rewrite Condition:RewriteCond %{REQUEST_URI} !^/\.well-knownPut this before the actualRewriteRule, this condition basically tells the server NOT to hide the.well-knownfolder.Make sure you clear your cachebeforetesting this.
I'm trying to allow access to a folder called .well-known but I've found this rule that blocks hidden directories;# block hidden directories RewriteRule "(^|/)\." - [F]Obviously there's a reason why this was added (I inherited the code) but I was wondering if I could keep this rule but add an exception for the .well-known folder?
.htaccess block hidden directories except one
My recommendation would be to use an httpdenvironment variable.This can act as a flag to inform your web application about the environment. Say you had a white label product, there it can be useful for example in setting what configuration should be used with a specific vhost.<VirtualHost *:80> DocumentRoot "/srv/www/foo/public" ServerName foo.com <Directory /srv/www/foo/public> # production | development | staging SetEnv APPLICATION_ENV development ...And then in your PHP code you would access it like:<?php define('APPLICATION_ENV_LOCAL', 'local'); define('APPLICATION_ENV_DEVELOPMENT', 'development'); define('APPLICATION_ENV_STAGING', 'staging'); define('APPLICATION_ENV_PRODUCTION', 'production'); $app_env = (getenv('APPLICATION_ENV')) ? getenv('APPLICATION_ENV') : false; if (empty($app_env) || ! in_array($app_env, array(APPLICATION_ENV_LOCAL, APPLICATION_ENV_DEVELOPMENT, APPLICATION_ENV_STAGING, APPLICATION_ENV_PRODUCTION))) { throw new Exception("APPLICATION ENV IS NOT SPECIFIED OR IS INVALID."); }What I'd do is have totally separate config / INI type files that I include based on the environment. Those could determine error reporting behavior, maintain distinct database connections, anything else dependent on the application environment.
I have a virtual host in my WAMP local server, where I set my log file.I wanted to change my PHP log error level to only warnings and errors.The best way should be .htaccess, I tried this solution:How to disable notice and warning in PHP within .htaccess file?Dind't work (tried others also).At the end went to php.ini file, however is the less flexible options.1) Which are the priority of this level error instructions? (php.ini vs htaccess vs code) I guess that order?2) Why is not working in .htaccess? I just set it on top of .htaccess, and did't work.
PHP Error log level control: htaccess vs php.ini vs code and virtualhost
For redirects you need to usealwaysattribute:Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPSFrom themod_headers documentation:You're adding a header to a locally generated non-success (non-2xx) response, such as a redirect, in which case only the table corresponding toalwaysis used in the ultimate response.
I would like to add HTTP Strict Transport Security directive to my .htaccess file. I've added the lock at the end of the code here but when I test Testing the HSTS preload process it show the setting not set. I checked my Apache config and see the headers module enabled.What am I missing?<Files .htaccess> order allow,deny deny from all </Files> <FilesMatch "\.(png|gif|js|css)$"> ExpiresActive on ExpiresDefault "access plus 1 month" </FilesMatch> # disable directory autoindexing Options -Indexes ErrorDocument 400 http://%{HTTP_HOST} ErrorDocument 401 http://%{HTTP_HOST} ErrorDocument 402 http://%{HTTP_HOST} ErrorDocument 403 http://%{HTTP_HOST} ErrorDocument 405 http://%{HTTP_HOST} ErrorDocument 404 /incl/pages/error404.php ErrorDocument 500 http://%{HTTP_HOST} RewriteEngine On RewriteBase / RewriteCond %{SERVER_PORT} ^80$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L] # BEGIN GZIP <ifmodule mod_deflate.c> AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript </ifmodule> # END GZIP # Use HTTP Strict Transport Security to force client to use secure connections only <ifmodule mod_headers.c> Header set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS </ifmodule>I testedhereandhere.
Adding HTTP Strict Transport Security to .htaccess
This works for me# BEGIN Expires-Headers <IfModule mod_expires.c> <FilesMatch "\.(js|css)$"> ExpiresActive On ExpiresDefault "access plus 1 weeks" </FilesMatch> </IfModule> # END Expires-Headers # BEGIN Cache-Control-Headers <ifmodule mod_headers.c> <filesmatch "(gif|ico|jpeg|jpe|jpg|svg|png|css|js)$"> Header set Cache-Control "max-age=604800, public" </filesmatch> </ifmodule> # END Cache-Control-Headers
I'm trying to set theCache-Controlheader for the images in my Laravel 5.5 app. I'm using the.htaccessfile (placed in themyapp/publicdirectory):<IfModule mod_rewrite.c> # rewrite directives... </IfModule> <FilesMatch ".(jpg|jpeg|svg)$"> Header set Cache-Control "max-age=31536000, public" </FilesMatch>Unfortunately, theCache-Controlheader is not being set for the specified static resources, so I must be doing it wrong.Is it the .htaccess syntax I'm getting wrong, something Laravel-specific, or something else entirely?Update:I forgot to mention the server I'm working with - Nginx, which is an important clue,as it turns out.
Browser cache leveraging via .htaccess in a Laravel app not working
It may not be a problem everytime. Your .htaccess code may be alright. Please check permission of your root folder on godaddy server. It dependent on which type of server you use. Please enable to your folder permission on server. Then it may be working for you.
I uploaded a cakePHP project to the Godaddy server.I have also seen this link. But not solve the error:-500 internal server error occured in CakePHP 3?How to solve cakephp 500 Internal Server Error?CakePHP 500 Internal Server ErrorCakePHP shows 500 Internal Server ErrorMy .htaccess code in /root/.htaccess<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] </IfModule>In /root/app/.htaccess<IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule>In /root/app/webroot/.htaccess<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L] </IfModule>This error is still coming after a lot of effort.Please Help?
500 Internal server error CakePHP
You can just use aErrorDocumenthandler for403error instead of a rewrite rule like this:ErrorDocument 403 https://thedomain.com/Make sure to clear your browser cache before testing this change.
I am not very firm in Apache, so please excuse if the question might seem a bit obvious. I would like to redirect requests that would result in an Error 403 in specific directories to my webservers root by means of a .htaccess file. sohttps://thedomain.com/secretlair/->https://thedomain.comso far i used:RewriteEngine on RewriteBase / RewriteRule (.*) https://thedomain.com/$1 [R=301,L]which works but creates the problem of also redirectinghttps://thedomain.com/secretlair/thefile.txttohttps://thedomain.com/thefile.txtwhat do I need to change to make this work?Thanks a lot!
How do I redirect an Error 403 to root in .htaccess
After going through Apache documentation for log creation, I found that Apache not allowed to write code for log creation in .htaccess file. We need to write code in httpd.conf file.SourceMy code to write log file for all images in httpd.conf file is:SetEnvIf Request_URI "(\.gif|\.png|\.jpg|\.jpeg|\.JPEG|\.JPG|\.PNG|\.GIF|\.JFIF|\.TIFF|\.BMP)$" image-request=log CustomLog logs/unwanted-requests.log common env=image-request
I am trying to create a log file by using a.htaccessscript. I have a image directory in which I want to place the.htaccessfile which will write all file names which is accessed from this image folder.I now need to create a log inside image folder.I tried withRewriteLogbut it's not working for me. I am using Apache version 2.4.
Create log file using htaccess
Just set the upper bound:RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^[\w-]{0,25}$ /available.shtml [L]Instead of0,25, you could also try1,25if you wanthttp://yoursite.comto also be sent to/availablepage.
I have the following code in my .htaccess file that allows URLs that contain only letters, numbers, underscores or dashes to access my page (named "available"):RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^[a-zA-Z0-9_-]+$ /available.shtml [L]So for example, mywebsite.com/abc goes through, mywebsite.com/ABC goes through, mywebsite.com/123 goes through, mywebsite.com/aBc123 goes through (you get the point). Any requested url that containssymbolsproduces an error page.This works great, but I also want to restrict the character length to no more than 25 characters (Meaning the requested URL must contain only letters, numbers, etc. AND belessthan 25 characters long. How can I do this? I tried using:RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^([a-zA-Z0-9_-]{25,})+$ /available.shtml [L]but this makes it have to bemorethan 25 characters not less.edit(referring to comment):
How to rewrite a URL if its character length is less than a certain number of characters
Try something like the following near the top of your.htaccessfile. Using mod_rewrite:RewriteEngine On RewriteCond %{HTTPS} !on RewriteCond %{HTTP_HOST} ^(?:[a-z0-9-]+\.)?example\.com RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]What this says is... For all requests that are not HTTPS and that matchexample.comor<subdomain>.example.comthen redirect tohttps://on the same host, same URL-path.Note that this doesn't allowwww.<subdomain>.example.com(which I assume your SSL cert does not cover anyway).Change the302(temporary) to301(permanent) only when you are sure it's working OK.
I'm running a WordPress multisite network that allows users to optionally use a custom domain name on their websites. Users that opt not to use a custom domain are assigned a subdomain of the WP install (e.g.: fred.example.com, with example.com being the URL the WP multisite network is installed on).I have a wildcard SSL configured for the main domain, but I do not have certificates available for custom domain names.What I need is a htaccess rule to force traffic to https if the request is for eitherexample.comor*.example.com, but not if the request is coming in using a custom domain.It should work as follows:http://example.com/*→https://example.com/*http://foo.example.com/*→https://foo.example.com/*http://customdomain.com/*→http://customdomain.com/*
.htaccess rule to force SSL on only certain domains
Rather than do this in PHP, I suggest you implement it on the web server layer. Add this to the top of your.htaccessfile:RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]And remove your PHP redirect code.But this is still going to require log-in before the redirect is issued, with the details being transferred insecurely. What you really need is two<VirtualHost>blocks in Apache. One for port 80 that redirects requests for your directory to HTTPS, and one for port 443 that has the HTTP AUTH configured.UpdateAlso it makes no sense to try and issue a 302 redirect within a document that is used as the 403 error document, since the status code has already been set and the document is only being used to generate the body of that response, so it can't now change the response code to 302 because it has already been set to 403. The approach I've outlined above will work, or you could simply deny HTTP requests and serve HTTPS only for that directory.
I have a directory of my website I would like to secure. I am doing this using a .htaccess file to force a HTTP AUTH. I would like to force this HTTP AUTH to be done over HTTPS.Looking at various solutions on stack overflow here is the point I have got to:I have the following .htaccess file in the 'top_secret' directory:SSLRequireSSL ErrorDocument 403 /rd.php AuthType Basic AuthName "Secure Page" AuthUserFile "/home/usr/.htpasswds/public_html/top_secret/passwd" Require valid-userI then have 'rd.php' in my root directory:<?php $path = "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; if ( $_SERVER['SERVER_PORT'] == 80) { header("Status: 302 Moved\n"); header("Location: ".$path."\n\n"); } else { header( "Content-type: text/html\n\n"); echo '?'; } ?>This works quite well on my desktop computer, however when I browse to the top_secret directory from my iphone in safari (to the HTTPS or HTTP address) I just get a question mark returned. So for some reason the else condition of my php file is being outputted.I am not exactly sure what this means and how to resolve, any help would be greatly appreciated
Force HTTP AUTH over HTTPS
Problem appears to be due to the fact that you are placing redirect rule below your front controller rule that forwards everything toindex.phphence makingREQUEST_URIequal to/index.php.Have your rule like this:RewriteEngine On # Redirect to www RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] # RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # # If the requested path and file is not /index.php and the request # has not already been internally rewritten to the index.php script RewriteCond %{REQUEST_URI} !^/index\.php # and the requested path and file doesn't directly match a physical file RewriteCond %{REQUEST_FILENAME} !-f # and the requested path and file doesn't directly match a physical folder RewriteCond %{REQUEST_FILENAME} !-d # internally rewrite the request to the index.php script RewriteRule ^ index.php [L]Make sure you clear your browser cache before testing this change.
I know that there is a lot info out there on redirects from non www to www domain. But my problem is that I can manage the redirect of the home page, but not the subpages.You could see the examplehereSo when I enter the url like ourenglishclass.eu/fill-in-text-5th-6th-grade the redirect happens to the www.ourenglishclass.eu/index.phpI can see that there is probably more rewrite rules which cause it to behave this way, but I cannot find what, or how can I fix thisThese are the rules which redirecting to /index.php# RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] # # If the requested path and file is not /index.php and the request # has not already been internally rewritten to the index.php script RewriteCond %{REQUEST_URI} !^/index\.php # and the requested path and file doesn't directly match a physical file RewriteCond %{REQUEST_FILENAME} !-f # and the requested path and file doesn't directly match a physical folder RewriteCond %{REQUEST_FILENAME} !-d # internally rewrite the request to the index.php script RewriteRule .* index.php [L]I have tried these redirect rules from non-www to www:#RewriteCond %{HTTP_HOST} !^www\. [NC] #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]and (this is because i'm testing also with https)# Redirect to www RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ RewriteCond %{HTTPS}s ^on(s)| RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]Hopefully someone can point the way out
redirect all the pages from non www to www in htaccess
=~is used for regular expression based evaluation in expressions.Here is official Apache documentation for expressions.To negate use!~like this:<If "%{QUERY_STRING} !~ /foobar/"> Redirect 301 "/" "http://www.example.com/" </If>Check Binary Operators ListComparison operatorsName Description == String equality != String inequality < String less than <= String less than or equal > String greater than >= String greater than or equal =~ String matches the regular expression !~ String does not match the regular expression -eq eq Integer equality -ne ne Integer inequality -lt lt Integer less than -le le Integer less than or equal -gt gt Integer greater than -ge ge Integer greater than or equal
frequently I use this:<If "%{QUERY_STRING} =~ m#^.*TTT.*$#i">I would like to know what is =~? I suppose it's related to "equal". So how do I make "different"?
What does this symbol make inside htaccess
I have tried many ways to do this finally i found a pluginRemove slug from custom post typeThis works for me but this plugin is an old one and untested with my wordpress version. How ever its works for me.
I'm working on WordPress site and I use WooCommerce plugin. This plugin rewrites all my URLs likewww.mydomain.com/product/category/postname/but my client want to remove the/product/folder.By default the Permalink Settings in WordPress can't do that and WooCommerce team alsorecommendednot to remove the/product/folder. But I want my URL be likewww.mydomain.com/category/subcategory/post_id/postname/Can anyone help, please!
How to remove /shop or /product in URL WooCommerce
You can't match against querystring using a Redirec directive. You need to match against %{QUERY_STRING} variable using mod-rewrite. The following rule does what you want :RewriteEngine on RewriteCond %{QUERY_STRING} ^view=account&task=paypal$ [NC] RewriteRule ^/?index\.php$ http://example.com/paypal/? [R=307,L]?at the end of the destination url is important as it avoids appending old querystring to the new url.
PayPal are annoying...if you have thousands of customer subscriptions whichPOSTIPN's (Instant Payment Notifications) to a certain URL...you can never change that URL. If you want to have the IPN's sent to another URL, their advice...tell all your customers to cancel their subscriptions and start new ones after you've changed the IPN URL. Great.So after digging around, a solution I found is to use a 307 redirect which will not only redirect to a new URL, but carry along thePOSTdata with it. but I'm having a little trouble with that in Apache. It doesn't seem to work at all. Here is the line in my.htaccessfile:Redirect 307 /index.php?view=account&task=paypal https://api.anotherdomain.com/paypal/ipnWhat would be the reason this doesn't redirect?
Apache 307 Redirect to redirect POST data
Yes, you're redirecting anything starting with/so of course that includes/folder/and it just keeps redirecting. You can't redirect your whole site to a part of itself without excluding that part.Use this instead:RewriteEngine on RewriteCond %{REQUEST_URI} !^/folder/ RewriteRule ^(.*)$ /folder/$1 [NE,R=301,L]It will redirect anything that is not in/folder/.To only redirect the homepage, use this instead:RewriteEngine on RewriteRule ^$ /folder/ [R=301,L]
I am trying to redirect my entire site to a subfolder present in the root directory using the following Redirect command.Redirect 301 / http://example.com/folder/However, when I open the website, it gets redirected to something likehttp://www.example.com/folder/folder/folder/folder/folder/folder/folder...Am I doing something wrong here?
Redirect entire site to a sub folder
+100I just noticed it the variable you are matching against is%{ENV:HTTPS}, so , you can use the following rule in /projects/.htaccess :RewriteEngine on RewriteCond %{ENV:HTTPS} !on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]Clear your browser cache or try a diffrent browser to test this.
Probably I'm overseeing something very basic, htaccess is not my field of expertise.My site is https-only, to achieve this, the root folder / contains these lines:RewriteEngine On RewriteCond %{ENV:HTTPS} !on RewriteRule ^(.*) https://%{HTTP_HOST}/$1 [R=301,L]This works just fine. Now we have a new folder called /projects, which contains its own htaccess rules to translate the url in a database query by a file called /projects/project.htmlThe working htaccess within the folder /projects is:RewriteEngine On RewriteBase /projects/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ project.html?project=$1 [QSA,L]Now I would like to force https connection on this one, because the https rule in the main directory is not applied on /projects if you visit byhttp://URLdirectly. Therefore I modified the file to:RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://example.com%{REQUEST_URI} [R=301,L,NE] RewriteBase /projects/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ project.html?project=$1 [QSA,L]With this, it switches to https, but I keep getting "ERR_TOO_MANY_REDIRECTS".When I change the lines as @thickguru suggested, like this:RewriteRule ^(.*)$ https://example.com/$1 [R,L]It will redirect me tohttps://example.com/index.htmlright away.I fiddled around with the settings, also with the information ofthis post, however still I can't get it to work.
.htaccess Adding HTTPS forcing to existing rewrite rules of subdirectory
Your situation is not that uncommon. Try this (X-Forwarded-Protois de facto standard for identifying the originating protocol of an HTTP request):RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Our application needs to redirectHTTPrequests toHTTPS. Normally i would use theRewriteCondas below.RewriteCond %{HTTPS} offThe thing with our current hosting company is that the requested port is always 80. It doens't matter if we send aHTTPorHTTPSrequest, the$_SERVER['SERVER_PORT']is always 80.We can handle this inPHP, but we also want to force files toHTTPS.So the concrete question. Is there anyway to forceHTTPSin.htaccesswithout usingRewriteCondlikeRewriteCond %{HTTPS}orRewriteCond %{SERVER_PORT}.
Redirect HTTP > HTTPS when port is always 80
To anyone having the same issue, this is the code used to fix it:RewriteRule ^dex/([^/]*)/([^/]*)/([^/]*)/([^/]*)/?([^/]*)?$ /dex.php?one=$1&two=$2&three=$3&four=$4&five=$5 [L]Changed([^_]*)to([^/]*)and added?after what I wanted to make optional.In this case:/?is making a end slash optional, and([^/]*)?is making the last parameter optional. So it works when the URL is like this:http://example.com/dex/one/two/three/four/ http://example.com/dex/one/two/three/four http://example.com/dex/one/two/three/four/five http://example.com/dex/one/two/three/four/five/Hope this helps someone.
I have looked for the answer to my problem here, but the solution is always provided without explaining how to do it, that's the reason I can not do it properly.I have this code:RewriteRule ^dex/([^_]*)/([^_]*)/([^_]*)/([^_]*)/([^_]*)$ /dex.php?one=$1&two=$2&three=$3&four=$4&five=$5 [L]This htaccess as it is makes it mandatory that all parameters are given. This URL works:http://example.com/dex/one/two/three/four/fiveI also want to make it work like this:http://example.com/dex/one/two/three/fourMaking the last (or some) parameters optional. I read something about QSA|qsappend here:http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_qsabut I can't understand it completely.Any help? Thank you
Make optional parameter with .htaccess
Have it this way:SetEnvIf Request_URI /api api_uri AuthType Basic AuthName "Restricted Content" AuthUserFile /var/www/html/.htpasswd Require valid-user Satisfy any Order deny,allow Deny from all Allow from env=api_uri
I run a testsystem with a htaccess basic auth:AuthType Basic AuthName "Restricted Content" AuthUserFile /var/www/html/.htpasswd Require valid-userI now want to disable this auth for all user who target the /api and /api/orders etc. of this server. I tried it with this:SetEnvIf Request_URI "/api(.*)$" api_uri AuthType Basic AuthName "Restricted Content" AuthUserFile /var/www/html/.htpasswd Require valid-user Deny from all Allow from env=api_uri Satisfy anyBut this does not work - mod_setenvif is enabled. Does anybody have an idea why this is not working?Thanks!
.htaccess - Disable basic auth for specific path
First of all, you want to prevent access to your.htaccessfile, you can do that using:<Files .htaccess> order allow,deny deny from all </Files>You can then actually rename your.htaccessfile to help hide it from potential threats, it does not mean they can't find it.. but it certainly makes it harder!AccessFileName thehtfile.essThen, there are a number of methods you can use to help prevent "hacks". First of all, block any scripts that include the<script>tag in the URL:RewriteEngine On RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3E) [NC,OR]You can then block any script trying to set aPHP Globalsvariable via a URL:RewriteCond %{QUERY_STRING} GLOBALS(=|[|\%[0-9A-Z]{0,2}) [OR]Block any script trying to usebase64_encodevia URL:RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]Block any script trying to modify thea_REQUESTvariable via URL:RewriteCond %{QUERY_STRING} _REQUEST(=|[|\%[0-9A-Z]{0,2})Finally, disable the use of scripts on your directories..AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi Options -ExecCGILots of different options, and I imagine there are a lot more! These are some of the ones I use in my.htaccess. I hope these help to prevent similar attacks in the future! It really does suck :/
Closed.This question does not meetStack Overflow guidelines. It is not currently accepting answers.This question does not appear to be abouta specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic onanother Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.Closed7 years ago.Improve this questionLast night a shell script was able to execute some linux commands that modified my .htaccess files resulting in a simple redirect to an ad website. I've removed the redirect from the .htaccess but I'm trying to take preventative measures so that this does not happen again.I viewed the access log from my server and it shows these entries below:partners.xxxxxxxx.com-Jul-2016.gz:184.168.192.26 - - [03/Jul/2016:10:40:01 -0500] "GET /e5nbwvcxef.php HTTP/1.1" 200 61 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26" partners.xxxxxxxx.com-Jul-2016.gz:69.64.37.219 - - [03/Jul/2016:10:40:03 -0500] "POST /e5nbwvcxef.php HTTP/1.1" 200 20 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26"I remember a little bit ago that if the user has this kind of access it is bad. Can anyone shed some light on tips I can do to secure my server so they cannot upload things like this? Thanks!
shell script hijacked my .htaccess files [closed]
From:https://httpd.apache.org/docs/current/howto/htaccess.htmlThe configuration directives found in a .htaccess file are applied to the directory in which the .htaccess file is found, and to all subdirectories thereof. However, it is important to also remember that there may have been .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree. And those, in turn, may have overridden directives found yet higher up, or in the main server configuration file itself.If your htaccess is in the root, why the '../'? As it stands it is redirecting to an index.php above your root directory.If you want it to work for all requests, remove the two rewrite conditions. Right now it is saying: "rewrite request only if the request is not for a file or a directory that exists".
I have the following directory structure:root folder1 foldera file.php folder2 folderb index.php .htaccessI would like to route all requests to index.php and have this apply to all folders. Here is my .htaccess:RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]This seems to work fine forlocalhost/root. The request is correctly routed to index.php. But forlocalhost/root/folder1orlocalhost/root/folder1/foldera/filephpit does not work. Is there an additional rule I need to define for this to work?
Apply .htaccess to all subdirectories
You don't needRewriteCond %{HTTP_HOST}as you're matchingREQUEST_URIwhich you can do inRewriteRuleitself.You can use this rule in site root .htaccess:RewriteEngine On RewriteRule ^(.+)/([0-9]+)/?$ /$1/ [R=301,L,NE]
I want to make redirects from urls like/test/112321 to /test/ /test/test2/1311223 /test/test2/There are only digits in the end of the url.Now i haveRewriteCond %{HTTP_HOST} ^(.*)([0-9]*)/$ [NC] RewriteRule ^(.*)/([0-9]*)$ http://%1/$1/ [R=301,L]but it doesn't work. Could you help me with this?
Htaccess redirects from digits at the end
Try with:RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
I want to redirect all of my HTTP requests to my HTTPS (SSL) protocol. Please guys this is not a duplicate. I have already tried every question found on SO which indicate such question but none of them worked. I tried everything I found on the internet but still cannot figure out what the problem is. May be somewhere something has to be enabled or something like that.I want to redirect from myhttpd.conffile not from.htaccessbecause this is what suggested by Apache Org. My current Redirection Rule is<VirtualHost *:80> ServerName www.example.com Redirect / https://www.example.com/ </VirtualHost > <VirtualHost *:443> ServerName www.example.com </VirtualHost >I am making all of these changes in myhttpd.conffile located in/etc/httpd/conf/httpd.confAfter every change, I also restart my server with following/etc/init.d/httpd restartorservice httpd restartI also tried followingRewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]But still when I visit my site likewww.example.com, I am not redirected tohttps://www.example.com.I have a VPS Server so has enough access to my machine to enable or disable something.
Redirect not working in Apache, HTTP to HTTPS
Try this. I've been looking all over and this is the only way I could make it work...#non-www. http to www. https RewriteCond %{ENV:HTTPS} !on RewriteCond %{HTTP_HOST} ^(www\.)?yourdomain\.com$ RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L] #non-www. https to www. https RewriteCond %{ENV:HTTPS} on RewriteCond %{HTTP_HOST} ^yourdomain\.com$ RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]
I have a site with Wordpress. I need some single page to redirect HTTPSI get code form stackoverflow and put in .htaccess# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTPS} off RewriteCond %{THE_REQUEST} /online-order-auto [NC] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] RewriteCond %{HTTPS} on RewriteCond %{THE_REQUEST} !/online-order-auto [NC] RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress RewriteCond %{HTTP_HOST} ^(www\.)?site\.com\.swtest\.ru$ RewriteRule ^(.*)$ http://www.site.ru/$1 [L,R=301]The browser wrote "ERR_TOO_MANY_REDIRECTS". I cant understand whats a problem
HTTP to HTTPS - Too many redirects
You just need to addhtml5Mode(true)in your route provider configuration. Make sure that you are passing the parameter $locationProvider on config function as an argument.here us the sample js code:var serviceBase ="http://admin-pc/eDemo/admin/test/"; app.config(['$routeProvider','$locationProvider', function ($routeProvider,$locationProvider) { $routeProvider .when('/add', { controller: 'addController', templateUrl: serviceBase + 'add', controllerAs: 'vm', }) .when('/edit', { controller: 'editController', templateUrl: serviceBase + 'edit', controllerAs: 'vm', }) .otherwise({ redirectTo : 'list' }); $locationProvider.html5Mode(true); }And your HTML should looks like below :<div class='ng-view'> <base href="<?=url('/').'/'?>"> </div>Also Keep in mind that never pass#in anykind of url like you redirecting , you submitting form through AJAX or anywhere.
My url: eDemo/admin/test/list/#/listI want: eDemo/admin/test/listjs:var serviceBase ="http://admin-pc/eDemo/admin/test/"; function config($routeProvider, $locationProvider) { $routeProvider .when('/add', { controller: 'addController', templateUrl: serviceBase + 'add', controllerAs: 'vm', }) .when('/edit', { controller: 'editController', templateUrl: serviceBase + 'edit', controllerAs: 'vm', }) .otherwise({ redirectTo : 'list' }); }html:<div class='ng-view'></div>
how to remove '#' from url in angularjs
In .htaccess file changeRewriteBase /toRewriteBase /assets
This is my structure:- app - assets - css - js - views index.html - vendor .htaccess index.php.htaccessRewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(assets|bower_components|dist)/(.*)$ /app/$1/$2 [L,NC] RewriteCond %{REQUEST_URI} !^assets|bower_components|dist/.*$ RewriteRule ^ index.php [L,QSA]My problem is that when I try to load:/assets/css/style.cssfromindex.htmlit gives me404.Why is this happening?
Slim .htaccess static files issue
You can create an exception like this:RewriteEngine On RewriteMap lc int:tolower RewriteCond %{REQUEST_URI} [A-Z] RewriteCond %{REQUEST_URI} !/P\d+/?$ [NC] RewriteRule (.*) ${lc:$1} [R=301,L]Or using negative lookahead:RewriteCond %{REQUEST_URI} [A-Z] RewriteRule ^(?!.*/P\d+/?$)(.*)$ ${lc:$1} [R=301,L]
I'm trying to redirect uppercase URL's to lowercase, but having a bit of a nightmare with it! (Mainly because my .htaccess knowledge is lacking!)Currently I have:<IfModule mod_speling.c> CheckSpelling on </IfModule> RewriteEngine On RewriteMap lc int:tolower RewriteCond %{REQUEST_URI} [A-Z] RewriteRule (.*) ${lc:$1} [R=301,L]Which works fine, but the CMS I'm using puts pagination links in the URL such ashttp://website.com/blog/P8orhttp://website.com/blog/P10and because the URL's have an uppercase P (Which seems to be required) they are 404 or 301 redirecting.Is there a rule i could add to make it not pick up on segments of the URL that have aPand immediately have at least one numerical character after it? Regex maybe?Any help would be appreciated!
Redirect uppercase URL's to lowercase except *** - htaccess
There are a couple of problems. You need to put the ruleABOVEyour wordpress rule because wordpress rules routeeveryrequest to index.php. Next you will need to usemod_proxywith the use of the[P] flagbecause regardless of not specifying redirect in the rewriterule, Apache will do it anyway because the substitution URL is a new domain. So Apache will perform a Redirect. So using[P] flagshould proxy the content instead of doing a redirect. This should accomplish what you need.RewriteEngine On RewriteRule ^wp-content/uploads/(.*)$ https://BUCKET.s3.amazonaws.com/wp-content/uploads/$1 [P] # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
I'm trying to redirect my uploads folder to my s3 bucket using htaccess in wordpress however it's not working. All the images on my site are still getting served locally from the server instead of linking to the bucket.This is my htaccess file:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress RewriteEngine On RewriteRule ^wp-content/uploads/(.*)$ https://BUCKET.s3.amazonaws.com/wp-content/uploads/$1 [L] # BEGIN W3TC CDN <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$"> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> </FilesMatch> # END W3TC CDN
Redirect wordpress uploads folder to s3 bucket using .htaccess
Also exist other posibility. You can try to change all special characters with this "(.*)" in the RewriteRule.
I have a problem with a redirect rule that doesn´t work with spanish special characters. I dont know how can i convert my word to type into the htaccess file, because the charset supported by htaccess file doesn´t recognice de Á, É, etc characters. Do you know can i set the redirect rule for something like:Redirect 301 /home/BÁSICO.pdf http://example.com/exampledocument.pdforRedirect 301 /home/MÉDICOS.pdf http://example.com/exampledocument.pdf
Apache htaccess spanish accent
Use this line in your root .htaccessRewriteRule ^test.php$ /testing/sub/test.php
I am stuck in here with htaccess. I've searched and tried many tutorials and problem solutions but couldn't achieve what I want.I want to remove folder names from the website link. My htaccess file is in the root directory i.e "testing"What my link looks like:http://localhost/testing/sub/test.phpWhat I want:http://localhost/test.phpFollowing is my htaccessRewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule /(.*) /testing/sub/$1 [L]
Remove folder names from the URL using htaccess
You caninsert this rule just belowRewriteBaseline:# send any request containing multiple / to 404 RewriteCond %{THE_REQUEST} // RewriteRule ^ - [L,R=404]
This is my URL structurehttp://example.com/filename-.html.htaccessRewriteEngine on RewriteBase / RewriteRule ^filename-([0-9]+)\.html$ filename.php?id=$1 [L] RewriteRule ^(.*)\.html$ $1.php [L] ErrorDocument 404 /404.htmlissue is that if there is a wrong url it doesn't go to 404 error pageExample wrong urlshttp:///example.com/filename-18-bank/////-4.htmlhttp://example.com//////listing-560.htmlHow can i tell .htaccess to redirect these url to 404 error document.
.htaccess show 404 error if url has extra slashes
Finally I've figured out the issue by spending an entire day. Here is the solution.Updated virtual host entry.<VirtualHost *:80> ServerName example.com DocumentRoot /var/www/example.com/ # Additional section added to get the htaccess working in sub folder. Alias /website_name/ /var/www/example.com/website_name/ <Directory /var/www/example.com/website_name/> Options Indexes FollowSymLinks MultiViews AllowOverride all Order allow,deny allow from all </Directory> </VirtualHost>
I've tried to host a CodeIgniter website in Ubuntu server.All other websites are working fine without any issues (the sever contains WordPress and Laravel applications). But this particular CodeIngniter website is not taking .htaccess file. I've spend a day to figure out the issue, but no luck.Here is the details.Website url structure:http://example.com/website_name.htaccess file<IfModule mod_rewrite.c> RewriteEngine on RewriteCond $1 !^(index\.php|resources|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule>Virtual host entry<VirtualHost *:80> ServerName example.com ServerAlias example.com DocumentRoot "/var/www/example.com" <Directory "/var/wwww/example.com"> Options Indexes FollowSymLinks MultiViews AllowOverride ALL Order allow,deny allow from all </Directory> </VirtualHost>CodeIgniter config file$config['base_url'] = 'http://example.com/website_name/'; $config['index_page'] = ''; $config['uri_protocol'] = 'REQUEST_URI';And when I'm trying to access the website the output is as follows,Not Found The requested URL /website_name/test was not found on this server.But if I add index.php, the the website is working without any issues. I've tried lot methods and it doesn't worked.
.htaccess not working - CodeIgniter
You can use negation:RewriteEngine on ErrorDocument 503 /503.html RewriteRule !^503\.html$ - [L,NC,R=503]
htaccess for apache server cause all my IIS servers will be down on maintenance. I need to redirect everything to error 503 custom page and also return the 503 error, but I don't know the correct sollution.RewriteEngine on RewriteBase / ErrorDocument 503 /503.html RewriteRule ^.*$ - [L,NC,R=503]This result into this: (the response is not my custom response)Service Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.Another try:RewriteEngine on RewriteBase / ErrorDocument 503 /503.html RewriteRule ^(?!503.html)$ - [L,NC,R=503]Gives me what I need but just for www.domain.com and every other page gives me 404 (except www.domain.com/503.html which gives me 200).So what I need is to redirect every page but the domain.com/503.html to custom 503 error page and also return the error code.
Redirect all but one page to error 503 custom page
As it turns out, with the default XAMPP configuration there is no need toC:\xampp\apache\conf\httpd.conf, hence no need to restart Apache as we are just making changes toC:\xampp\htdocs\www.johndoe.com\.htaccess. Asthis post on RewriteBaseexplains, we do not needRewriteBasesince we will not use absolute paths in the destination links for.htaccessrules. Since relative links in these destination rules will be relative to the directory we are serving out of, we need delete thewww.johndoe.comdirectory from the rule, as follows:Place the.htaccessin ``C:\xampp\htdocs\www.johndoe.com`.Place the following rewiterule in it:RewriteEngine on RewriteRule ^about/?$ index.php?value=about
I am running XAMPP for Windows 5.6.11. I have the following PHP file:C:\xampp\htdocs\www.johndoe.com\index.phpwhich I am accessing ashttp://localhost/www.johndoe.com/As a matter of fact I need to access the following page:http://localhost/www.johndoe.com/?value=aboutas either of the following two:http://localhost/www.johndoe.com/about/ http://localhost/www.johndoe.com/aboutso I have the following in my .htaccess file:RewriteEngine on RewriteRule ^www\.johndoe\.com/about/?$ www.johndoe.com/?value=aboutHowever, this is not working, as accessing the former sites gives me a 401 (not found).Here is what I have inC:\xampp\apache\conf\httpd.conf:<Directory /> AllowOverride none Require all denied </Directory> DocumentRoot "C:/xampp/htdocs" <Directory "C:/xampp/htdocs"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Require all granted </Directory>What must I do to get my.htaccessfile to be parsed and carry out the substitution I'm after?I have tried placing the following inC:\xampp\apache\conf\httpd.conf:<Directory /> AllowOverride all Require all allowed </Directory>but have had no luck with it. I have even tried changing my.htaccessfile to the following:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteBase /www.johndoe.com/ RewriteRule ^about/?$ ?value=aboutbut I'm still getting the 404 not found error message.
XAMPP .htaccess mod_rewrite not working
Kindly check name of class you given to home.php Controller
I am new to codeigniter. I have just made a login feature in CI with the help of google, but here I am redirecting to URL on login but It is not working. Here is the details after redirecting the link is like thishttp://localhost/xpensepedia/index.php/homewhich is giving the 404 error404 Page Not Found The page you requested was not found.and my controller ispublic function index() { $this->load->view('header'); if (($this->session->userdata('user_id') != "")) { redirect(site_url('home')); } else { $this->load->view("register"); } $this->load->view('footer'); }My files are in the image
Codeigniter redirect URL issue
+100This is by design and intentional. WordPress rewrites have become increasingly complex over the years, and many plugins utilise thepageendpoint for a page (usually with a template and custom query) - redirecting introduces a potential world of pain.Long story short, it doesn't matter anyway. WordPress adds<link rel="canonical />for pages, so no need to worry over duplicate content.Update:For localised situations where you want to disregard the potential risks, this will canonicalize all page URLs - note that it does not check if a page is actually paginated (i.e. with the<!--nextpage-->quicktag) and will break this feature if you use it.function wpse_199180_canonical_pages( $wp ) { if ( ! is_admin() && is_page() && isset( $wp->query_vars['paged'] ) ) { wp_redirect( get_permalink( get_queried_object() ), 301 ); exit; } } add_action( 'wp', 'wpse_199180_canonical_pages' );
I seemingly to have a strange issue I have found in almost every other Wordpress site.Suppose, you have set your Blog home to a static WP page/myhome. And you have a separate page for blog/blog.Now, this works fine and should be:/blog /blog/page/2 /blog/page/3 /blog/page/4But, for all other pages, e.g./about-us, these links also work:/about-us/page/2 /about-us/page/3 /about-us/page/4And show the content of the/about-uspage.My problem is that/about-us/page/2should ideally redirect to/about-us(it's canonical URL) since there are no paginations in any other page except the/blog.What am I missing there ? This seems to happen on almost all sites I have checked and is really frustrating from SEO point of view.
Wordpress Redirecting Non Category Pages /page/nnn to their Canonical URLs
The.htaccessfile won't load up because it is in thepublicdirectory, which is really meant to be your document root. As such, you should be accessing the app by going tolocalhost/page/public/subpage.If you want to uselocalhost/page/subpagewhilst keeping your directory structure intact, then you need to add a new.htaccessfile to thepagedirectory, anddeletethe.htaccessfile from thepublicdirectory./page/.htaccesscontents:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteBase /page/ # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Send requests to public directory... RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^ public/index.php [L] </IfModule>Unfortunately, due to the way in which Laravel obtains the request information, you will need to group your routes to thepagedirectory in your route configuration:Route::group(['prefix' => 'page'], function() { Route::get('subpage', ['as' => 'subpage', 'uses' => 'GenericPageController@subpage']); // Your other routes ... });Essentially, and in my opinion, this is the easiest way to work around this. You could also move the contents of yourpublicdirectory up one level and change the paths accordingly in the bootstrap file.
Yes there, have been similar questions, but the suggested solutions are not working for me. So I've set up Laravel, and the installation works fine. Well, as long as I'm staying on the base routelocalhost/page/as soon as I'm trying to hit one of my routes, let's saylocalhost/page/subpageand the route is configured to return a viewRoute::get('subpage', ['as' => 'subpage', 'uses' => 'GenericPageController@subpage']);The methodsubpagein the Controller:public function subpage() { return view('base.subpage'); }I simply get a 404 response from the server whenever i try hitting one of the routes. It doesnt matter what controller I'm using, or if its returning a view or a closure.mod_rewrite is enabledOn the main directoryAllowOverrideis set toAllmy.htaccessin thepage/publicfolder looks like the following:<IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteBase / # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [L]Anyone has an idea what the problem could be?
Laravel 5 Apache mod_rewrite not working
You have to reorder yourRewriteCondslike this:RewriteEngine On RewriteRule \.jpg$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteRule \.jpeg$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteRule \.gif$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteCond %{REQUEST_URI} !^.*/maintenance/.*$ [NC] RewriteRule \.png$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteCond %{REQUEST_URI} !^.*/maintenance/.*$ [NC] RewriteRule \.php$ /mysite/maintenance/maintenance.php [NC,R=302,L]RewriteConddirective affects only the firstRewriteRuleafter it.
I have a .htaccess that contains the following :<Files .htaccess> order allow,deny deny from all </Files> Options +FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_URI} !^(.*)/maintenance/(.*)$ [NC] RewriteRule ^(.*).jpg$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteRule ^(.*).jpeg$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteRule ^(.*).gif$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteRule ^(.*).png$ /mysite/maintenance/transparent.png [NC,R=302,L] RewriteRule ^(.*).php$ /mysite/maintenance/maintenance.php [NC,R=302,L]Tested on localhost.With these settings, I have an infinite loop when trying to loadhttp://localhost/mysite/test.php, (correctly) redirected tohttp://localhost/mysite/maintenance/maintenance.phpThe loop seems to be due to the 4 image redirection (note : the maintenance page has a one an unique jpg background image located in the maintenance folder root). Commenting these 4 redirection lines solves the problem.But I don't see why I enter in an infinite loop as the /maintenance/ path is itself excluded from redirection in the RewriteCond, and why the redirection on the images can interfere with this problem.Can you help ?
.htaccess - preventing infinite loops with URL rewriting
If you don't want to avoid DB queries for this you can apply a simple technique in filename to indicate remaining limit Like filename-10, filename-9 etc. But to use this approach u need to update the part after "-" on each download.This could be one approach.
I am creating a website , which people can create their own video and can download it from my server.I want to limit the download count to 10.So What I am planning is to serve a download file via a php file and update the count of the file to database.If it reaches 10 downloads.I deny the download.But I guess it consume more resource.Is there any other way possible in linux server such as using htaccess or something like that ? So after a file is accessed 10 times it should be automatically deleted.EDIT : its not users...any people can use this website for free.
limit number of times the file can be downloaded
You can allow access to the image folder for the mobile versionRewriteCond %{QUERY_STRING} !^desktop RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|iphone [NC] RewriteCond %{REQUEST_URI} !^/ProImages/ [NC] RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]
I'm redirecting my website to mobile website when access through a mobile device.Here's the htaccess code:RewriteCond %{QUERY_STRING} !^desktop RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|iphone [NC] RewriteRule ^ http://m.example.com%{REQUEST_URI} [R,L]Folder structure of FTP is like this:Images ProImages Mobile // All mobile site data into thisWhen I attempt to accesshttp://www.example.com/ProImages/abc.jpgfrom my mobile website, it doesn't show up because as soon as it tries to callwww, it redirects tom.I tried using../ProImagesbut that again didn't solve the issue.Anybody can help in this?
Access folder of parent website from mobile website after htaccess redirect
Add the following line to your.htaccessfileAddHandler application/x-httpd-php .doThis tells the server to process all files ending with.doas.php.
How can I hide the normal PHP filename extensions and use my own extensions?For example, usingexample.doinstead ofexample.php.I want files with the the.dofilename extension to be treated as PHP files, so that I can accessexample.do. How can I do this?
Using .do extension as .php extension for all php files
To ignore changes in a file, usegit update-index --assume-unchanged .htaccessThis command sets a flag on the file such that Git treats it as if there are no uncommitted changes to the file, regardless of the contents of file your working copy.You need to undo the previous before you can stage and commit new changes.git update-index --no-assume-unchanged .htaccess git commit .htaccess
Here's the scenario:I want to track .htaccess in my repo, since it contains essential configuration.I want to keep prying eyes away from my dev site, so I add HTTP auth directives to .htaccess in dev.During development, I don't want Git to constantly tell me that .htaccess is modified, nor do I want .htaccess to be included in anygit add -Acommand.I do, however, want the option to add and commit .htaccess. (If I make changes that should propagate to production.)What's the best way to do this? Thanks for your advice.
Git: ignoring .htaccess… just not always
You can exclude it inRewriteRuleitself:RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule !^validation http://domain2.com%{REQUEST_URI} [NE,NC,R=301,L]
I'm trying to redirect all urls from one domain to another but one (kind of). This is the htaccess I have to redirect all keeping the same url except of the domain (for example domain.com/something goes to domain2.com/something).RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^domain.com$ [OR] RewriteCond %{HTTP_HOST} ^www.domain.com$ RewriteRule ^(.*)$ "http://domain2.com/$1" [R=301,L]What I want to know is how to redirect all except if the url is domain.com/validation/*/validation/ is not a subfolder and it has to be the next part of the url after the domain (domain.com/something/validation can redirect, and domain.com/validation/something can't).I tried a lot of options but none worked :(I hope is enough information.
Htaccess - Redirect all but one url
There's nothing you can do except renew your certificate.The warning is opened by your browser,beforeany request is ever even sent to the server. When it tries to resolve an HTTPS request, it first establishes the SSL handshake with the server, this is where the server gives the browser the certificate and the browser sees that it's expired. The browser then displays a security exception/warning. That means there isnothingthat you can do on the server's end to prevent this from happening except addressing the certificate.After you've renewed your cert, you need to have a rule to redirect all HTTPS traffic to HTTP traffic using a 301 redirect.
In the past I had a ssl certificate but I don't have it anymore because I didn't use it. However, now I see that some of the my website's page are indexed on google with https. Clicking those links directs you to a security warning. How can I best solve this? I tried adjusting the htaccess file redirect https requests to the http protocol, but that doesn't remove the warning. Any help?
How to get rid of an ssl security warning with expired certificate
Most likely new server hasMultiViewsoptions enabled by default. Place this line on top of .htaccess to disable it:Options -MultiViewsOptionMultiViewsis used byApache's content negotiation modulethat runs beforemod_rewriteand and makes Apache server match extensions of files. So/filecan be in URL but it will serve/file.php.
I want to pass url parameters but parameters are not passing on to the desired page.Earlier my site was hosted on cpanel and below code works successfully but after I shifted my site to VPS Server with Cent OS Webpanel with Varnish Cache and apache running on server, the parameters are not passed on target page/url.RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^download/(.*).html download.php?q=$1 [L,QSA]I want to run the url:www.example.com/download/anything.htmland target url after rewrite iswww.example.com/download.php?q=anythingThe problem is that rewriterule is working but parameters are not passed.But if I use the below code the parameters are passing Successfully.RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-zA-Z_0-9-]+)$ download.php?q=$1 [L,QSA]or below codeRewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*) download.php?q=$1 [L,QSA]and I am running the below url, the parameters are passed to target page successfullywww.example.com/anythingtarget url:www.example.com/download.php?q=anythingbut I want the URL in the following formatwww.example.com/download/*****.htmlreplace *Asterisk Sign with actual query.If I add some static text to the Rewrite url likedownload/(.*).htmlthe parameters are not passed to target page.Thanks
.htaccess rewrite parameters not passing to target page
Yes, your$wgScriptPathis wrong. Use:$wgScriptPath = "/";Your rewrite rules also seem unlikely to be what you desire, especially that^.*$ /index.php(although it might be harmless, coming last).If you are using a root url instead of a normal short url you will need to use the following instead (to ensure that existing files and directories are not seen as article, e.g. "/index.php" "/images" etc.):RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/w/index.php [L](Source)
I have a Mediawiki installation running on my web root. E.g. the main page can be accessed viahttp://example.com/index.php?title=Main_PageI would like to change it so that the short URL ishttp://example.com/Main_PageMy configuration is as follows#.htaccess Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)$ /index.php?title=$1 [PT,L,QSA] RewriteRule ^.*$ /index.php [L,QSA].// LocalSettings.php $wgScriptPath = ".."; $wgArticlePath = "/$1"; $wgUsePathInfo = true;But I get a 500 error with this configuration.This is a server where there is a~/user_root/folder. This folder contains the public HTML files for the root domain of the user, e.g.user-root.com.The folder contains several subfolders, e.g. in this case~/user_root/example, which is accessible via the mentioned URL above,example.com.Is the problem based on this folder/subfolder hierarchy and the$wgScriptPathsetting? Should$wgScriptPath = "..";be replaced by something else than this relative path? Please advise, if you need more information.
Short URL for Mediawiki installation in web root
First, make suremod_rewriteis enabled.Then, also make sure you can usehtaccess(Apache config ->AllowOverride All).Put this code in your htaccess (assuming it is in root folder, like yourindex.phpfile)RewriteEngine On RewriteRule ^viewall$ /index.php?route=product/category&path=0 [L]
For my opencart site, I'm using a vQmodshow_all_product.xmlso that the path/index.php?route=product/category&path=0shows all my products on a category page. It's working perfectly, but ideally what I would like to do is use a SEO friendly URL to achieve this, e.g./viewallwould give the same page.I would much appreciate if someone could point me in the right direction.
Opencart seo url for view all products page
There is an easier solution.Add this line to the beginning of your .htaccess file:Options -IndexesThis way, you won't be able to see the folder contents.EDIT: htaccess rule solution (which is inwebsitefolder)ErrorDocument 404 /website/inc/404.php RewriteEngine On RewriteBase /website/ RewriteRule ^teachers/$ - [R=404,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [L]
I have myquery stringto include my pages, in my homepage like you see below and it is working fine, Im including my pages fine.But something wrong is happening and Im not finding how I can solve this.I will try to expain my isse with an example:I have a folder "teachers" inside I have two pdf documents and a page "documents.php". To acess this documents page, Im acessing: "htp://localhost/website/teachers/documents", and it is working fine.But If I acess "htp://localhost/website/teachers/", Im able to acess my pdf documents and my page as you see in my image below.But I dont want this, I want that If some user tries to acess "htp://localhost/website/teachers/", I want to include my 404 file (require_once('inc/404.php');)My query string:@$url = $_GET['url']; $url = explode('/', $url); $url[0] = ($url[0] == NULL ? 'index' : $url[0]); if(file_exists('inc/'.$url[0].'.php')){ require_once('inc/'.$url[0].'.php'); } elseif(file_exists($url[0].'/'.$url[1].'/'.$url[2].'.php')){ require_once($url[0].'/'.$url[1].'/'.$url[2].'.php'); } elseif(@file_exists($url[0].'/'.$url[1].'.php')){ require_once($url[0].'/'.$url[1].'.php'); } else{ require_once('inc/404.php'); }Do you see what Im doing wrong to not be having the result I want?My htaccess file:RewriteEngine On RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1
I want my users to only access my php files, if they try to access the folders I want to include my page 404 file
You simply can't allowexec(and other similar functions disabled by php.ini) through .htaccess.
I need to enable php_exec function which is in php.ini file. Since, I am using shared hosting, I do not have access to php.ini file. How can i enable the same function through .htaccess file?Please provide the syntax.Many Thanks in Advance.FYR :exec() has been disabled for security reasonsRegards, Natu
Enable php_exec function through .htaccess
Found it!This article from theme.fmmentions that thematches[n]array only works for groups in the regex surrounded by parentheses. For example:To get $matches1to return 'human' when going to 'planets/animals-and-more/animal/human', the rewrite rule would need to look like this:add_rewrite_rule('^planets/animals-and-more/animal/([a-zA-Z0-9-_]+)$','index.php?pagename=sponsorship&sponsorship_item=$matches[1]','top');with () around the group you want to 'match'.
I am trying to match the following url:planets/animals-and-more/animal/humanTo:index.php?pagename=animal&animal-name=humanWhere the page 'animal' has a custom page-animal.php template that pulls in the 'animal-name' query variable and spits it into an .I have set up the rewrite tag:function animal_custom_rewrite_tag() { add_rewrite_tag('%animal-name%', '([^&]+)'); } add_action('init', 'animal_custom_rewrite_tag', 10, 0);And the rewrite rule(s):function add_some_rewrite_rules() { global $wp_rewrite; add_rewrite_rule('^planets/animals-and-more/animal/[a-zA-Z0-9]*$','index.php?pagename=animal&animal-name=$matches[4]','top'); $wp_rewrite->flush_rules(); } add_action( 'init' , 'add_custom_ncta_rewrite_rules' );The rewrite rule works if I hard code a string in like 'animal-name=monkey', but it seems like thematches[n]array doesn't work at all.I know this is all possible by modifying htaccess, but I need a solution for Wordpress.Any idea why $matches[] doesn't work at all?
Wordpress add_rewrite_rule Not returning $matches[] array items
Let's take an example URI/abc:Your first regex:^([^/]+)/?$Matches/abcand rewrites it to:/index.php?ToDo=abcNowmod_rewriteengine runs again and matches the regex^([^/]+)/?$again for URI/index.phpand rewrites it to:/index.php?ToDo=index.phpYour 2nd regex:^([^/.]+)/?$works fine because it doesn't match/index.phpURI.Best way to write this rule is like this:RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/?$ index.php?ToDo=$1 [L,QSA]These twoRewriteCondlines will prevent rewriting if request is for a valid file or directory.
In my .htaccess file I have:RewriteEngine On RewriteBase / RewriteRule ^([^/]+)/?$ index.php?ToDo=$1 [L,QSA]When doing a print_r($_GET), it outputsArray ( [ToDo] => index.php )however, when I change the Rewrite Rule to^([^/.]+)/?$ index.php?ToDo=$1 [L,QSA]print_r then outputs that $_GET is an empty array. Can someone explain to me why this occurs?
Why does $_GET = index.php
Place this rule in your/legalHQWithNewAddressTable/legalHQ/public/admin/.htaccess:Options -MultiViews RewriteEngine On RewriteBase /legalHQWithNewAddressTable/legalHQ/public/admin/ RewriteRule ^Parties/caseid/([0-9]+)/?$ Parties.php?caseid=$1 [L,QSA,NC]
Disclaimer : I dont know anything about URL rewritingcurrently my URL looks likelegalHQWithNewAddressTable/legalHQ/public/admin/Parties.php?caseid=7 (any number basically)But how can I make it to looks like the followinglegalHQWithNewAddressTable/legalHQ/public/admin/Parties/caseid/7/I'm trying but not workingRewriteRule ^([a-zA-Z0-9]+)/?Please dont make things complicated I dont know anything about URL rewriting so please keep it as simple as possible.Any Idea?
.htaccess file I can't make it working
Some urls that don't need to be rewritten are getting rewritten. You probably want to change your rule like this:RewriteEngine On RewriteRule ^([^/.]+)/?$ page.php?title=$1 [L]The[^/.]ensures that there is no dot in the pathThe+ensures that there is at least one characterThe/?allows an optional trailing slash
Getting values in php while using.htaccessRewriteEngine RuleI am using the following ruleRewriteEngine On RewriteRule ^([^/]*)$ page.php?title=$1 [L]It means it will create a page like view(i.e.,)www.mywebsite.com/contactwww.mywebsite.com/blogBut how can i get values that is passed in the url and display it inside the page using Get methodecho "Page content is ".$_GET['title'];While i pass the value in the url like www.mywebsite.com/view,It is just displaying > Page content is page.phpWhat mistake i am doing and how can i fix this ?
Getting values in php while using `.htaccess` RewriteEngine Rule
You need to add this rule just belowRewriteEngine Online to send all the URLs with multiple slashes to 404 handler:RewriteCond %{THE_REQUEST} \s/+(.*?)/+(/\S+) [NC] RewriteRule ^ [L,R=404]If for some reason you you want strip off multiple slashes use:RewriteCond %{THE_REQUEST} \s/+(.*?)/+(/\S*) [NC] RewriteRule ^ %1%2 [R=302,L,NE]
I have been working on my.htaccessfile, to make navigation experience much easier. According to the syntax provided by Apache Foundation?will only allow a character or word be written once or zero times, but that doesn't seem the case. For some reason its allowing me to duplicate as many characters I want. Below is the problem with more detail.RewriteRule ^contact([/]?)$ contact.phpThat line work's perfectly for what I want, but I would like to know why its allowing me to do thislocalhost/contact////////////////////////and not onlylocalhost/contactorlocalhost/contact/as it is supposed to.localhost/contact////////////////////////should go to the specified404 HTTP ERRORpage.This seems to be a problem with Apache as I have realised stackoverflow contains the same problemhttps://stackoverflow.com/unanswered//////
.htaccess Mod Rewrite should not allow extra characters
Have your first rule like this:RewriteCond %{HTTP_HOST} !^stage\.mydomain\.com$ [NC] RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
How would I exclude a subdomain from getting forced to https and redirected to main url? I'm using the below in my .htaccess file but need a little help as my subdomain (stage.mydomain.com) gets redirected / can't access.<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{SERVER_PORT} !^443$ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>I've tried a few options but no luck - Any ideas? Thanks!
.htaccess force https but exclude a subdomain
It usesPerl Compatible Regular Expressions. You can pretty much find all the information you are looking forright here in the docs. The short answer is yes, it supports both.
Moreover, does it support named capturing groups and backreferences?
What regex flavour does Apache's mod_rewrite use?
Place this rule in/admin/.htaccess:RewriteEngine On RewriteBase /admin/ RewriteRule ^$ login [L]
quick question:Using tutorials I have been able to redirect my domain name to point to a different page other than the index.phpHowever I cannot find any tutorials or reference material to help me in changing the default page for a particular sub-directory.For example, I want www.url.com/admin to redirect to www.url.com/adming/login whilst still showing www.url.com/admin in the address bar.I'm sure this must be fairly simple but I can't quite get my head around in.Many thanks in advance.
.htaccess Set Default Page for each Sub-Directory