Response
stringlengths 8
2k
| Instruction
stringlengths 18
2k
| Prompt
stringlengths 14
160
|
---|---|---|
You can add this to your .htaccess:RewriteRule ^([^\.]+)$ $1.html [NC,L]taken from:http://www.sicanstudios.com/how-to-remove-php-html-htm-extensions-with-htaccess/ | I had a Dynamic PHP website which I needed to convert into a static website to give to a client. I usedwgetto pull the files and it did exactly what I needed. The only problem is..my links before (the ones indexed in google) have no file extension. I used .htaccess to get rid of the .php file extension.So one of my URL's would look like this:http://www.domain.com/about/When I got a static version of the website, it changed all of my links to .htmlThat could be fine, as I could use htaccess to get rid of that file extension and so all of my links will be the same as before. Well, all of the internal linking in each page is linking to the .html version.Is there a way with htaccess to direct users if they go to about.html it will take them to about with no extension? So all of my internal linking will still work?Or is there any other suggestions you guys might have on how to handle this?Here is the wget code I use:wget -k -K -E -r -l 10 -p -N -F -nH http://www.domain.com/How can I get that to output .php files instead of .html?Thanks! | PHP Website Converted to Static HTML site - Linking Issue |
.htaccess grammar is actually the exact same as the Apache configuration itself, and example parsers do exist for it.If you're looking to write your own, you are mostly correct on the format. Remember, section tags can be nested and can have parameters (like <Location />)English method of parsing:For each line in the file:
Strip whitespace from beginning and end of line.
If the line starts with a '#':
Parse it as a comment (or skip it)
Else, If the line starts with a '<':
If the next character is a '/', the line is a closing tag:
Seek to the next '>' to get the tag name, and pop it from the tag stack.
Else, the line is an opening tag:
Seek to the next '>' for the tag name.
If the tag, trimmed, contains whitespace:
Split on the first whitespace. The right side is params, left is the tag.
(IfModule, Location, etc use this)
Push the tag name to the tag stack.
Else, the line is a directive:
Split the line on whitespace. This is the directive and params.Just add quote handling and you're set. | Bet you didn't see this coming? ;)So, a project of mine requires that I specifically read and make sense out of.htaccess files.Sadly, searching on Google only yields the infinite woes of people trying to get their own.htaccessto work (sorry, couldn't resist the comment).Anyway, I'm a bit scared of trying to get this thing out of open-source projects that use it. See, in the past few weeks, I ended up wastinga lotof time trying to fix my issues with this strategy, only to find out that I did better to read RFCs & specs and build the thing my way.So, if you know about a library, or any (hopefully clean!) code that does this, please do share. In the mean time, if you know about any articles about .htaccess file format, I'm sure they'll be very handy. Thanks.NB:I'm pretty much multilingual and could make use of any codebase, even though the end code will be Delphi. I know I'm asking too much, but I'd love to see less of C++. Just think of my mental health before sharing C++ code. :)Edit:Well, I think I'm just going to do this manually myself. The file structure seems to be:directive arg1 arg2 argN
<begin directive section>
</end directive section>
# single line comment | Tokenize .htaccess files |
The challenge comes with having to detect and account for four different possible domain patterns:example.com → example.nlexample.co.uk → example.nlsub.example.com → sub.example.nlsub.example.co.uk → sub.example.nlSo, what this ruleset does is checks that the TLD is not .nl (preventing a loop from occurring), then pulls the subdomain, www or not, off the front (read as "capture anything other than a dot followed by a dot, optional), followed by the base domain, followed by a dot. We don't have to match the entire URL, since we aren't keeping the TLD.RewriteEngine On
RewriteCond %{HTTP_HOST} !example\.nl$
RewriteCond %{HTTP_HOST} ^([^.]+\.)?example\.
RewriteRule ^ http://%1example.nl%{REQUEST_URI} [NC,L,R=301]The RewriteRule's ^ matches any URL, then inserts the contents of the first set of parens in the preceding RewriteCond (the subdomain) with %1, and completes the rewriting by appending the requested path and flags to ignore case, make this the last rule, and redirect with a search-engine-friendly 301, ensuring the rewritten URL appears in the user's browser. Any query string (text appearing after a ? in the URL) is automatically included by default. | I am trying to rewrite the following url:the subdomain should match any subdomain. same for the TLD.
both:http://car.example.com/andhttp://cat.example.co.ukshould be rewrittenhttp://subdomain.example.com/some/dirtohttp://subdomain.example.nl/some/dirandhttp://example.com/some/dirtohttp://exampkle.nl/some/dir(also with www. adress)but my knowledge of htaccess and rewrite rules in general aren't good enough for this :(I hope one of you knows the solution.ps. I did try a search ;) | htacces rewrite tld without changing subdomain or dirs |
You can use below code to make that work:RewriteCond %{HTTP_REFERER} http\:\/\/example.com/([a-z]+)/videos/
RewriteRule (.*)$ /login/%1/I tried on my domain.. and it works... hope that too work with you... :) | I've an issue where i want to redirect a user on the basis of a substring from referered url, How i can accomplish that using htaccess?User is onhttp://example.com/aqeel/videos/There is a hyperlink on the above pagehttp://demo.example.com/When user reacheshttp://demo.example.com/, I want him to be redirected tohttp://demo.example.com/login/aqeel/, Here aqeel is the substring captured from the referer url in htaccess from step 1 URL.Thanks in Advance, | Redirect on the basis of referer HTTP_REFERER htaccess |
There are often more efficient ways than IP bans. For example, hidden fields in a form only bots will fill out, or requiring javascript or cookies for submitting forms.For IP banning, I wouldn’t use .htaccess files. Depending on your webserver it may read the htaccess files for each request. I’d definitely add the IP-bans into your webservers vhost configuration instead. That way I’d be sure the webserver will keep it in RAM and not read it again and again.Doing it via PHP would also be an option. This way, you could also easily limit the bans to forms, like registration in your forum. | I run a large forum and like everyone else have issues with spammers/bots. There are huge lists of known spam IP's that you can download and use in htaccess form, but my only concern is the file size. So I suppose the question is how big is too big, given it's going to be loading in for every user. Adding all the IP's in it gets to about 100kb.Is there an alternative that would have less overhead? Possibly doing it with php, or will that result in some heavy load too due to file size and checking ips etc?Any advice would be greatly appreciated.Thanks,Steve | IP Banning - most efficient way? |
You could condense them into a single rule as well:RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ http://sub.example.com%{REQUEST_URI} [R=301,L]Mark's point about the/is an important consideration. Since you're defining the rule in.htaccessthough, the input (and by association the captured backreference) will not start with a leading slash, so you actually do need an explicit one in this case (like you had).Since we just want the whole path anyway, using%{REQUEST_URI}is more reliable in this sense because it will always have a leading slash, regardless of the context we're using the rule in. | I need to redirect from a main domain like mydomain.com or www.mydomain.com to sub.mydomain.com - and this needs to work for all requests, so mydomain.com/whatever goes to sub.mydomain.com/whatever.I've tried this, which only works for non-www at the main domain:RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://sub.mydomain.com/$1 [L,R=301] | 301 Redirect from main domain (www and non-www) to subdomain |
Personally for the "x-ua-compatible" tag, i went for the .htaccess directive. I followed thehtml5boilerplatetemplate:# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------
# Force the latest IE version, in various cases when it may fall back to IE7 mode
# github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
BrowserMatch MSIE ie
Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
</IfModule>
</IfModule>
<IfModule mod_headers.c>
# Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
# We need to inform proxies that content changes based on UA
Header append Vary User-Agent
# Cache control is set only if mod_headers is enabled, so that's unncessary to declare
</IfModule> | In HTML5, some meta elements do not validate (yet?) like:<meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1">
<meta http-equiv="imagetoolbar" content="no">Are Conditional Comments an appropriate solution here resp. will meta elements still work as expected?<!--[if IE]><meta http-equiv="x-ua-compatible" content="ie=emulateie7;chrome=1"><![endif]-->
<!--[if lt IE 7]><meta http-equiv="imagetoolbar" content="no"><![endif]-->Using a .htaccess file instead of meta elements (not always possible unfortunately), would this be the right way to go?<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
# BrowserMatch MSIE ie OR?
BrowserMatch MSIE emulate_ie7
# Header set X-UA-Compatible "IE=EmulateIE7" env=ie OR?
Header set X-UA-Compatible "IE=EmulateIE7" env=emulate_ie7
BrowserMatch chromeframe gcf
Header append X-UA-Compatible "chrome=1" env=gcf
</IfModule>
</IfModule>Thanks! | How to handle meta elements not validating in HTML5? |
YourRewriteRuleattempts to createPATH_INFOin a per-directory context, which, from what I can tell, occurs too late in the request processing phase to work correctly.The best solution is to simply not do this, as CodeIgniter doesn't require it to function:RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.phpCodeIgniter should be able to figure out what the proper request was on its own, provided that you left$config['uri_protocol']set toAUTO. If not, you should set it to eitherAUTOor toREQUEST_URI. | I'm trying to useCodeigniter OpenID libraryand everything work fine with default configuration ofCIwithout.htaccess.When I removeindex.phpby changingconfig.phpand.htaccessI get404 Page Not Foundwhen I try to verify my openid (http://ci.dlsb.eu/test/)Can anybody tell me where I'm wrong?config.php$config['index_page'] = "";.htaccessRewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L] | Codeigniter, OpenID and .htaccess |
The nicest solution in my opinion: installmod_xsendfilein your Apache, have the PHP script authorize the user, and on success send a response with anX-Sendfileheader pointing to the location of the protected file. From that point on, Apache does the work of serving the file to the client; not PHP. | I need to serve up large files (> 2gb) from an Apache web server. The files are protected downloads, so I need some kind of way to authorize the user. The CMS I'm using uses cookies checked against a MySQL database to verify the user. On the server, I have no control over max_execution_time, and limited control over memory_limit.My technique has been working for small files. After the user has been authorized in PHP (by the CMS), I use readfile() to serve the file, which is stored above the document root to prevent direct access. I've read about techniques to chunk the download or to use fpassthru to get around the PHP memory limit. But I haven't found a technique to get around the max_execution_time limit.I thought about storing the file within the document root, so we could bypass PHP entirely. But what I can't figure out is how to restrict access with htaccess. I need to verify the user against the database before I can serve them the file.Thanks. | Serving Large Protected Files in PHP/Apache |
Answer from original poster:Finally found the right place: /etc/apache2/sites-available/default
search for the<directory /var/www/> part, and changed it to:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory> | I tried to write a .htaccess file on my local pc's website,I've realized I need to set AllowOverride All instead of None
searched, found the file /etc/apache2/conf.d/security
in the file I found#<Directory />
#AllowOverride None
#Order Deny,Allow
#Deny from all
#</Directory>changed it to<Directory />
AllowOverride All
Order Deny,Allow
Deny from all
</Directory>typedservice apache2 restartand... .htaccess still didn't work :Ithe file by the way, holds one line, deny from all. | Changed the AllowOverride to All and still nothing |
The reason the file is not served via mod_python when you delete .htaccess is because the setup for mod_python is located in it. If you move that stuff to your sites-available file, you can delete .htaccess, turn a blind eye to the problem, and call it a day.If that doesn't satisfy you, then as to why .htacess is being read at all, I can't say. You are correct that AllowOverride Noneshouldprevent the file from ever being read. Have you considered the possibility that you screwed something up when adding the virtual site? Try throwing some garbage into the config and see if it complains, just to be sure it's being read at all. | This is the opposite problem from most about which I have read. I am running Ubuntu 8.04 on an Amazon instance with Apache 2.2.8 and I can't figure out why setting AllowOverride to None for root doesn't stop my .htaccess file from being included.I have a sub-directory with hello.py in it and an .htaccess file. When I browse to the file, it works fine with modpython serving the file. If I put some garbage in .htaccess I get a server error, so I know the .htaccess file is being used. Also if I delete the .htaccess file, hello.py is no longer server by modpython - instead the browser tries to open it.In one of my sites-available (linked in sites-enabled), I have "AllowOverride None" for the root directory. I thought that this would prevent .htaccess from being included from root and all its sub-directories which should cause hello.py to not be served by mod_python. However, it continues to be served fine and I can test that .htaccess is still being included because when I modify it, I see the results in my browser.Maybe there is something I am not understanding about my file in sites-enabled. This is the file I am using:NameVirtualHost *:8080
<VirtualHost *:8080>
<Directory />
AllowOverride None
</Directory>
</VirtualHost>Thanks for any help. | Why can't I disable .htaccess in Apache? |
+25One way is to rewrite/apifrom the main .htaccess file in the root directory like this:RewriteEngine On
RewriteBase /
RewriteRule ^api/(.*)$ ../subdir/api/$1 [R,L,QSA]The .htaccess file in the new /subdir/api folder can stays the way it is. Only the RewriteBase needs to be adjusted.Another way is to rewrite from the previous/apifolder if you preserved it for some reason:RewriteEngine On
RewriteBase /api
RewriteRule ^(.*)$ ../subdir/api/$1 [L] | I have a shared hosting on A2Hosting and I recently moved my main domain frompublic_html/topublic_html/subdir/Here's the structure:/public_html
/subdir(site files of main domain)
/api
index.phpMy current htaccess(public_html) is :RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.
RewriteRule ^(.*)$ /subdir/$1 [L]When I called my APi before it was :domain.com/api/But now it's :domain.com/subdir/api/My htaccess inapiis :RewriteEngine On
RewriteBase /api/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]How to remove the "subdir" in the url to keep my api like previous ? But still point the root to my subdir with my current htaccess ?Thanks | Slim 3 - remove subdir from url with rewrite rule |
After contacting 123-Reg (my hosting provider), they submitted this solution, which works perfectly:RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]Basically they have set the script to do two tasks: Change domain toWWW, if it isn't already, THEN change toHTTPS. Also, they usedENV:HTTPS, which is different to what was found in their documentation (ENV:SSL).Glad to have to this sorted, and maybe this will help out others using 123-Reg Hosting. | I have made a .htaccess file to redirect all website traffic tohttps://www..This is my complete .htaccess file:RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]The below redirects work exactly as expected:http://example.com -> https://www.example.com
https://example.com -> https://www.example.com
https://www.example.com -> https://www.example.comExcept:http://www.example.com -> http://www.example.comAs shown above, if you go tohttp://www.it doesn't redirect to the HTTPS version.Can anyone help me understand why the other redirects are working fine, but that one is not?Additional Notes:I have looked at a number of posts on StackOverflow, but most of their solutions end in redirect loop errors. | .htaccess file not redirecting http://www. to https://www |
To deny access to all sub-directories of the /project folder, you can use the following mod-rewrite Rule inproject/.htaccess:RewriteEngine on
#if the request is for existent dirs, forbid the request
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [R=403,L]This returns a 403 error response if you request a directory that exists.If you want to do this for both files/directories, you can use the following redirectRedirectMatch 403 /project/.+/.*$ | Say that I have the following directory structure:/
/opt
/opt/lampp
/opt/lampp/htdocs/
/opt/lampp/htdocs/...
/opt/lampp/htdocs/.../projectAnd then within theproject/directory, I have the following directory structure:project/
project/.htaccess
project/index.php
project/dashboard.php
project/theme.css
project/...
project/subdir-1
project/subdir-1/...
project/subdir-2
project/subdir-2/...
project/subdir-3
project/subdir-3/...What do I write inproject/.htaccessto allow access to all files in theproject/directory, but deny access to all the sub-directories (i.e.subdir-*) and all the files in each sub-directory?Here is what I have so far:.htaccess# Deny access by default
Order deny,allow
Deny from all
# Allow access to all PHP/CSS files in current directory
<Files ~ "[^/]\{0,}\.(php|css)$">
Allow from all
</Files>I'm basically trying to allow access to all PHP/CSS files, except for files with a'/'in the file name; however, the result is that I am unable to access anything. What would be the correct way to accomplish this?Also, is there a cross-platform way to do this (i.e. So that it would work on both UNIX/Linux & Windows servers)? | How to deny access to all subdirectories of current directory with .htaccess? |
update your code with below and have a read the comments tooOptions +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule> | How can I achieve all of this using htaccess. Thus far I have--RewriteEngine OnTo remove index.phpRewriteCond %{REQUEST_URI} ^system.*
RewriteCond $1 !^(index\.php|images|js|uploads|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-dTo enforce SSL and non www to wwwRewriteRule ^(.*)$ index.php/$1 [L]
RewriteCond %{HTTP_HOST} !^(www|abc|cde|efe) [NC] #Subdomain abc and cde
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]know why its happening but can't figure out a rule to combine everything I need and make it work.need force to https and remove index.php and non-www to www.Answers will appreciated and thanks in advance | Forcing HTTPS with www and remove index.php .htaccess in CodeIgniter |
In Chrome it is forwarded correctly tohttps://www.fit-for-easa.com-
but not in Firefox what seems very strange to me.
Firefox shows ssl_error_bad_cert_domain.It does not work in Chrome either for me. Maybe it worked for you because you've added an exception earlier. The reason is simple: the namefit-for-easa.comis not included in the certificate, only the name with thewwwprefix. From the certificate:Subject: OU=Domain Control Validated, OU=PositiveSSL Multi-Domain, CN=3wertig.com
...
X509v3 Subject Alternative Name:
DNS:3wertig.com, DNS:www.fit-for-easa.com, DNS:www.steuerberatung-zodel.deTo redirect fromhttps://fit-for-easa.comto any other site your certificate has to include the name as shown in the URL, i.e.fit-for-easa.comand notwww.fit-for-easa.com. No htaccess settings or DNS settings can work around this, but the certificate has to be fixed. | I have a problem with redirections and didn't find a solution on the whole web...The right domain is: https://www.fit-for-easa.com
The following redirections DO work:
http://fit-for-easa.com to https://www.fit-for-easa.com
http://www.fit-for-easa.com to https://www.fit-for-easa.com
But the problem is with:
https://fit-for-easa.com
In Chrome it is forwarded correctly to https://www.fit-for-easa.com -
but not in Firefox what seems very strange to me.
Firefox shows ssl_error_bad_cert_domain.This is my .htaccess file:AddType image/svg+xml svg svgz
AddEncoding gzip svgz
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.fit-for-easa.com%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>Can it be that the problem is that the certificate is only for the www-Version but not for the non-www-Version? And that Firefox takes this critical whereas Chrome ignores it?Thank you for your help!(Sorry that I marked the text as code, but I don't have enough reputation to post more than two links - I'm working on it!) | .htaccess: non www to www (with https) shows ssl_error_bad_cert_domain in Firefox |
Try adding this to your Root/.htaccess :RewriteEngine On
RewriteBase /
RewriteRule ^en/?$ index.html [NC,L]
RewriteRule ^(ru|ua)$ index.$1.html [NC,L]This will redirect "/en" to "/index.html" and "/ru" to "index.ru.html". | I have a small portfolio landing page based on js/css/html. No frameworks/CMS, just pure static html. Entry point isindex.htmlfile with content on English language.I want to use translations on my site:index.ru.html,index.ua.html, but I don't want to see any*.htmlorindex.uain the address bar. User can change a language by buttons on top of my page.How can I route:http://mysite/ento displayindex.html- first enter to sitehttp://mysite/ruto displayindex.ru.htmlhttp://mysite/uato displayindex.ua.html?Also can I route to specific div/section html tag: user enterhttp://mysite/ru/contactsto display contacts section inindex.ru.html? Scrolling page also must change url... is it real or not?Maybe I need to use micro-framework for my small needs?EDIT:Found good example on this site -http://www.even.lv/ | Routing in static html landing page |
In my caseAllowOverride Allwas already in place for the whole/var/wwwdirectory, I just only had to add this intoDockerfile:# enabling mod_rewrite
RUN cp /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/ | I have a rewrite rule in my .htaccess like so:RewriteRule ^ /var/www/index.html [L](for an angular app's view routing)However, when I go to /anything I get 404. Any idea why this would be? Base docker container iseboraas/apache.My dockerfile:FROM eboraas/apache
RUN a2enmod rewrite
ADD . /var/www
EXPOSE 80Edit: also tried rule^.*$with no luck. it appears to be that .htaccess is not being used/is being ignored, not that the rule is wrongly configured. | Apache docker container - .htaccess rewrite rule 404 |
You can use this rule in root .htaccess:RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteRule (^|/)trackback/?$ - [F,NC] | I'm wanting to block POST requests to a specific URL on a website. Here is an example of a spammy POST request from my Apache log:110.86.178.xxx - - [14/Jan/2015:17:05:05 +0000] "POST /profile/example/trackback/ HTTP/1.1" 200 85 "http://example.com/profile/example/" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) )"I added the following code to the .htaccess file:# deny POST requests
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} POST
RewriteRule /profile/example/trackback/ [F,L]
</IfModule>Unfortunately I'm still receiving trackback emails, so it's not working.What is the issue and how can I fix this?
Also, how could I amend the code to block all POST requests sent to urls ending in /trackback/Thanks! | How can I block POST requests to urls ending with /trackback/ in .htaccess? |
in your .htaccess fileorder deny,allowdeny from allallow from your ip | This question already has an answer here:Need to deny all IPs except mine from accessing site and display friendly error(1 answer)Closed9 years ago.I am doing one application in php and i want to make the admin login secure for that i need to make the admin login functionality only from one ip address.So how can it be possible, please reply your help will be appreciated | Allow several ip address for admin login using htaccess files [duplicate] |
If I were you, I would use plugin instead of implementing from zero. You can usethisplugin for multilingual wp site. This plugin provides you three types of url structure;?lang=en/en/foo/en.yoursite.comIf you want to use for custom site, you can use following rewrite rule;RewriteEngine On
RewriteBase /
RewriteRule ^(en|da)/(.*)$ /$2?language=$1 [QSA,L]I assume, you are usinglanguageparam for languageEdit:There is some bugs on qTranslate plugin. That bugs can be solvable with additional plugin calledqTranslate Slug. Do not forget to use this additional plugin, if you faced url pattern problems | I am building a Wordpress website with two language support English and Danish.I want to keep the language code stringenfor English anddafor Danish prepended in request uri.Like: (Currently this is working for me)http://example.com/daIf i visit post or page, it should be map like this: (This is not working, getting 404)http://example.com/da/post-name
http://example.com/da/page-name
http://example.com/da/post/is/too/longI have also triedWordpress Rewrite APIadd_rewrite_rule()(Rewrite rules currently i have)<?php
add_action('init', function () {
add_rewrite_rule(
'^(da|en)/?', //Regex
'index.php?lang=$matches[1]', //request to
'top' //called earlier than wordpress rules
);
});and alsoadd_rewrite_tag(), but i think Wordpress just provide anadd_rewrite_endpoint(and i don't need this at all).I think it may only be possible with htaccess%{QUERY_STRING}conditions? (Don't know).htaccess contents:<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 WordPressEdit:I'm usingWP Native Dashboardfor translation on admin pages however on front i'm just using__()and_e()with.moand.pofiles and its working perfectly.P.S:This problem is not specific to Wordpress website, I also need this help with custom based websites in future. Provide me .htaccess rules/conditions if you can. | Keep the string prepended in request uri |
Yes, it's done by editing the httpd.conf file (turn on AllowOverride all) and creating a .htaccess file in your root web directory.Here is a sample .htaccess fileOptions -Multiviews
RewriteEngine On
RewriteBase /
RewriteRule ^l/(.*)$ /somescript.php?key=$1 [L]The above will directhttps://www.dropbox.com/l/I2QT40oSwU0AoH7g02cAHItohttps://www.dropbox.com/somescript.php?key=I2QT40oSwU0AoH7g02cAHI | Could someone point me in the right direction? I'm trying to create a url like the one below. I don't want to use url hashes#I2QT40oSwU0AoH7g02cAHIor parameters?myparam=I2QT40oSwU0AoH7g02cAHI.https://www.dropbox.com/l/I2QT40oSwU0AoH7g02cAHIIs this done with mod_rewrite?Many thanks! | Dropbox style URL, without using hashes or params |
Assuming you have mod_rewrite rules somewhere, you probably want to stick to mod_rewrite. You'll need to add these to the htaccess file in your document root, preferablyaboveany other rules that are there:RewriteEngine On
RewriteRule ^/?test-energy-reviews$ /s/test-energy-reviews [L,NC,R=301]
RewriteRule ^/?s/Test-Energy-Reviews$ /s/test-energy-reviews [L,R=301]TheNCflag ignores case, so it covers both/test-energy-reviewsand/Test-Energy-Reviews. The second rule takes care of/s/Test-Energy-ReviewsI'm not sure why/s/test-energy-reviews(3rd one) is one of your scenarios, since it is exactly what you want to redirect to. | I am new in htaccess.
I updated some SEO pages in my live site after one day some Url changes came so i changed the url again. but google already indexed it. So i want if some one found old url it will redirect to new url But in case of SEO pages only not for other pages.It means it wont affect to any other place.and there are not one page(it is 40-50 pages) can anybody give answer through htaccess or cakephp.Old Url-www.testenergy.com/test-energy-reviewsnew url-www.testenergy.com/s/test-energy-reviewsAnd there are also four senario-www.testenergy.com/test-energy-reviews
www.testenergy.com/Test-Energy-Reviews
www.testenergy.com/s/test-energy-reviews
www.testenergy.com/s/Test-Energy-ReviewsAll these four links will redirect towww.testenergy.com/s/test-energy-reviewsUrl only | forcibly redirect to correct folder |
It is not possible. Not because of ignore, but because of files from.hgcannot be tracked by mercurial.So you better create and check-in.htaccess.distwith template that fits most of your requirements and after you check out it on a particular machine - copy.htaceccess.distto.htaccessand make required changes in it. | I am using Mercurial for version control, and have an .htaccess file in my web root with rewrite rules that differ depending on whether it's my localhost or my development server, etc. Therefore, I have put ".htaccess" into my .hgignore file, so that it's not part of version control.However, I also have another .htaccess file, at .hg/.htaccess, with "deny from all", so that my .hg folder is not web accessible. I DO want THIS htaccess file checked in to version control, so that there's no chance of me forgetting to set it up on a new server, etc.Is there a way to do this? It seems as if just putting ".htaccess" into my hgignore makes it ignore all .htaccess files, located anywhere. I tried "./.htaccess", hoping that'd ignore the root level one, but not .hg/.htaccess--didn't work though. I've tried doing research and have not had much luck.Thanks, and sorry if I missed something obvious somewhere! | Mercurial selectively hgignore htaccess files |
You could rewrite all URLs that don't map to an existing file, using:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>Then grab the actual URL via$_SERVER['REQUEST_URI']. Here's an example:$parts = parse_url($_SERVER['REQUEST_URI']);
$user = $parts['path'];Seehttps://github.com/zendframework/ZendSkeletonApplication/blob/master/public/.htaccessfor an example. | I'm programming a website which has a lot of users stored in a mysql_database where each user has an ID and profilename (likejim.button.1) among other fields. I want an url (which get's the profile through e.g a mysql_select on the userID) that has this structure:www.mysite.com/jim.button.1Now I know that I could do that with a mod_rewrite_rule, but with thousands of users I'll get a very large .htaccess file. I'm not by far an expert in mod rewrite by the way, but I understand how it works.Is there a way to do this, say in one or two mod_rewrite_rules or is there another smart way to accomplish this?All help is welcome. | creating thousands of urls through mod-rewrite |
Try:RewriteCond %{HTTP_HOST} !^energenie4u\.co\.uk$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://energenie4u.co.uk/$1 [R=301,L] | I'm looking to redirect all of:http://
http://www.
https://www.
to https://This may have been answered here before, but having gone through the questions that seem relevant they are all not quite what I'm after, and everything I've tried resulted in a redirect loop or not working as hoped.For example:RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www.example.com
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{HTTPS_HOST} ^example.com
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]Thanks in advance for your help. | .htaccess redirect both http:// with and without www and https://www to https:// non-www |
What I'll explain is for multilanguage websites, but you can very easily apply this to what you're asking: rename "LANGUAGE" to "var" (smile).Here's what you may want to do, to be able to handle in the future many sub languages.
Check your host: if it contains a "known language", add it in a global variable (= environment variable from Apache's point of view) then at the end, if the "language" variable is not set, set is as the default language. And finally, add it as a parameter.<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.([^.]+)\.website\.com$
RewriteRule ^(.*)$ "http://www.website.com/$1?var=%1" [P]
RewriteCond %{HTTP_HOST} ^(www\.)?(us|fr|pt)\.mydomain\.com$
# Create an environment variable to remember the language:
RewriteRule (.*) - [QSA,E=LANGUAGE:%2]
# Now check if the LANGUAGE is empty (= doesn't exist)
RewriteCond %{ENV:LANGUAGE} ^$
# If so, create the default language (=es):
RewriteRule (.*) - [QSA,E=LANGUAGE:es]
# Add the language to the URI (without modifying it):
RewriteCond (.*) $1?language={ENV:LANGUAGE} [QSA]
</IfModule>(note: please, please... use proper indentation). | This question already has answers here:Closed12 years ago.Possible Duplicate:Apache rewrite based on subdomainIs it possible to rewrite a URL like this?www.foo.website.com/some-pagetowww.website.com/some-page?var=fooI'm asking about a rewrite (I think that's what it's called) and not a redirect. i.e. I want the first URL to stay in the address bar, but for the server to "get" the second URL.I've never understood how to do URL rewrites and so far my pathetic attempts to get this working have failed miserably :-)I should add that this .htaccess file is also being used by WordPress and has the following code:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~kbj/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /~kbj/index.php [L]
</IfModule>Any help or advice would be very much appreciated! | How to rewrite a subdomain to a variable in a URL? [duplicate] |
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) http://www.%2.com/?name=%1 [R=301,L]rewriteshttp://subdomain.domain.comtohttp://www.domain.com/?name=subdomainto combine the two try something like thisRewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^(www)\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.com [NC]
RewriteRule (.*) http://www.%2.com/index.php?route=$1&name=%1 [R=301,L]that will redirecthttp://subdomain.domain.com/hello-worldtohttp://www.domain.com/index.php?route=hello-world&name=subdomain | I have the following already in my.htaccessfile:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]But I want to add a rule like this:RewriteCond %{HTTP_HOST} ^(.+).example.com
RewriteRule ^(.*)% http://example.com/?name=%1&type=$1 [R,L]But without it binding toexample.comand it must work on any domain. | htaccess - subdomain as GET parameter |
If you can, you may move your.htaccessdirectives into theVHost file.Using the VHost will be faster because apache will not read the .htaccess everytime a page is loaded, the VHost will be executed when apache loads.(Reference:Move .htaccess content into vhost, for performance) | I am planning on redirecting about 100 using (301 .htaccess) and was wondering if this will slow down the performance or have any effect since the file will get heavy ?Are there any types of entries in .htaccess that affect performance more than others ?Example:redirect 301 /old page.shtmlhttp://www.example.com/newdir/newpage.shtml | Will lots of entries in .htaccess file slow site access down? |
Try adding the following to the.htaccessfile in the root directory of your site (public_html)RewriteEngine on
RewriteBase /
#prevent looping from internal redirects
RewriteCond %{ENV:REDIRECT_STATUS} !200
#only rewrite gif, jpg or png
RewriteRule ^(images)(/.+\.(gif|jpg|png))$ $1/%{HTTP_HOST}$2 [L,NC]Your ruleRewriteRule ^[^/]*/images(.+) images/%{HTTP_HOST}/$1did not work because you have a leading/beforeimages. In .htaccess the leading/is removed, so the rule would never match. | My software supports multiple domain names all pointed at the same directory on the server (a different database for each of course). So these domains...www.example1.com
www.example2.com
www.example3.com...all point to.../public_html/In the image directory.../public_html/images/I have directories that exactly match the host names for each website:/public_html/images/www.example1.com/
/public_html/images/www.example2.com/
/public_html/images/www.example3.com/I'm trying to get Apache to rewrite requests so that if you view the image directly and look at the address bar you only see the host name once.So a request for...http://www.example1.com/images/book.png...is fetched by Apache at.../public_html/images/www.example1.com/book.pngOne of the things I've tried and have had success with in different circumstances is the following though it doesn't work in this situation:RewriteRule ^[^/]*/images(.+) images/%{HTTP_HOST}/$1 | Apache Rewrite: image directory based on HTTP host |
use this:RewriteEngine on
RewriteCond %{HTTP_HOST} ^blog\.domain\.com [NC]
RewriteRule (.*) http://domain.com/blog/$1 [R=301,L] | I've researched this for about 2 hours now and although most of the topics are similar, none have explained how to do what I'd like to do.I'm taking a blog that had a structure of blog.domain.com and moving it to www.domain.com/blog/. I need to keep the permalink of the blog post when I redirect so...blog.domain.com/here-is-a-blog-post/should become:www.domain.com/blog/here-is-a-blog-post/After trying many things, this is the last thing I tried which ends up having no affect at all. Meaning blog.domain.com just sits at blog.domain.com/RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz\.domain\.com$
RewriteRule ^/(.*) http://domain.com/$1 [redirect,last]Here's the entry from my httpd.conf file.<VirtualHost xxx.xxx.xxx.xxx:80>
SSLEngine off
SuexecUserGroup apache apache
ServerName www.domain.com
ServerAlias domain.com
ServerAlias blog.domain.com
ServerAdmin[email protected]DocumentRoot /home/domain/www/domain.wiredground.com
ScriptAlias /cgi-bin/ "/home/domain/www/cgi-bin/"
<Directory /home/domain/www/cgi-bin>
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory>
</VirtualHost>Can anyone help?Thanks! | Apache rewrite from subdomain to www but keep all permalinks |
In your .htacces file use this:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)(\/?)$ /index.php/$1/$2 [NC,QSA,L]ORin your httpd.conf<VirtualHost *:80>
DocumentRoot "/var/www/"
ServerName www.url.com
ServerAlias www.url.com
<Directory /path/to/www/>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/(.*)(\/?)$ /index.php/$1/$2 [NC,QSA,L]
</Directory>
</VirtualHost>If you use PHP:$_SERVER['REQUEST_URI']will have/asd/asd | I want to rewrite URLs so when someone goes to:url.com/directory1/directory2He sees the URL in the browser address bar but actually the following URL is showing the texturl.com/index.php/directory1/directory2So basically, the URLurl.com/directory1/directory2goes tourl.com/index.php/directory1/directory2How can I do that using .htaccess and/or mod_rewrite? What is the rewrite rule for that? | mod_rewrite URLs |
Just remove the portion that says that it should serve directories:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]Now it will serve files (with size > 0) and symbolic links directly, but send directory references and other urls to your application | I have such situation.
I'm developing application in Zend Framework and htaccess pointing every request to
index.php. If some file or directory exists on the request path then htaccess allow access to this files like css, js, images etc...Now I have for example such link:example.com/profile/martin-slicker-i231With Zend Router it points to controller account and action viewprofile. I want to add some avatart for my users and I created directory in public folder (so the images would be accessible by the server like css and js). The directory is named "profile" and subdirectory in it is "martin-slicker-i231". All path is visible by server like that:public/
.htaccess
index.php
profile/
martin-slicker-i231/
avatar-small.jpgThe problem is when i point browser to example.com/profile/martin-slicker-i231 it
points me to this directory not the controller and action. When I remove the folder with user then the flow go to the controller and action. How to configure .htaccess so theexample.com/profile/martin-slicker-i231will be pointing to controller and action but request toexample.com/profile/martin-slicker-i231/avatar-small.jpgpoint to the file. Here is my .htaccessRewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]Can somebody help? | htaccess block access to directory but allow access to files |
Most likely; you don't have the PHP module loaded for your webserver. This means that then the server finds a application/x-httpd-php file, it passes it directly to the client instead of running it through a PHP interpretor (which would run any PHP code and output a text/html content type). Since browsers don't include PHP interpretors, they treat it as any other unknown content type, and offer to save it to disc. | I added the following line to.htaccess:AddType application/x-httpd-php .html .htmWhen I try to load any page on the side, my browser tries to DOWNLOAD the page! What am I doing wrong?Thanks! | .htaccess causes all pages to be downloaded |
+25You can also try thisRewriteEngine onFor week :RewriteRule ^index/(\d+)$ index.php?week=$1 [NC,L]For page:RewriteRule ^index/(\w+)$ index.php?page=$1 [NC,L]For both week and page:RewriteRule ^index/(\d+)/(\w+)$ index.php?week=$1&page=$2 [NC,L] | I have modified my .htaccess file right now to remove the .php extension to my website. I also have a rule to have a pretty url. My problem however is I'm not sure how to add a second parameter. In addition I wanted to know if it was a problem for the rules if these parameter aren't set.For example as of now my rules will change mywebsite.com/index.php to mywebsite.com and mywebsite.com/login.php to mywebsite.com/login and mywebsite.com/index.php?week=1 to mywebsite.com/1.However I have now added a new parameter and my url will now be mywebsite.com/index.php?page=a?week=1 and I would like it to be change to mywebsite.com/a/1 However the "week" or the "page" parameter arent always going to be set. So it could sometimes just be index.php?week=1 or index.php?page=a or they could both be set.Here are my current rules:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^([0-9]+)$ index.php?week=$1
RewriteRule ^([0-9]+)/$ index.php?week=$1Is what Im asking for even possible? | .htaccess remove php extension with pretty url of multiple parameter |
You can use this rule at the top of your .htaccess:RewriteCond %{QUERY_STRING} ^(.*&)?stage=Stage(?:&(.*))?$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [L,R=301,NE] | I have a URL that looks something like this:https://www.example.com/about-us?stage=Stage&utm_source=abc&utm_medium=xyzI want to just remove the stage=Stage part.I tried the below code:RewriteCond %{QUERY_STRING} ^stage=Stage$
RewriteRule (.*) $Stage? [R=permanent]but it only seems to work if the URL is:https://www.example.com/about-us?stage=Stagewithout the rest of the parameters.How can I make the other parameters pass over apart from the stage=Stage parameter? | .htaccess - Remove one query parameter from URL |
Thanks for your help, I wanted to post the solution I found in a wordpress forum here:https://wordpress.org/support/topic/htaccess-help-301-redirects-not-working/Thanks to @markrh for his answer. The problem was that I needed to move my 301 redirects above the WordPress section at the top. My rules were never getting reached cause the WordPress part catches all of them. | I have two identical versions of a website, both using different AWS EC2 instances(staging xx.xx.xx.xx and production xxx.xxx.xxx.xxx). I want to create a 301 redirect that redirects all users from the staging site to the production site, UNLESS they are visiting from my IP. I thought this was a relatively simple task, but I have attempting to make this work for the last couple hours with no resolution. I am hoping that someone here will be able to point me in the right direction. Currently, the redirect works for visitors to the homepagehttp://xx.xx.xx.xx, but it does not work for other pages such ashttp://xx.xx.xx.xx/page1or the ec2 public DNS likehttp://ec2-xx-xx-xx-xx.us-west-1.compute.amazonaws.com/Here is my entire .htaccess file, the redirect I added is the last one. Any help you could give me would be much appreciated!!# 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>
php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300
# END WordPress
RewriteEngine on
RewriteRule ^(.*)$ http://newsite.com/$1 [L,R=301,NC]
RewriteBase /
RewriteCond %{HTTP_HOST} !newsite.com$ [NC]
RewriteCond %{REMOTE_ADDR} !=xxx.xxx.xxx.xxx | Why is this .htaccess redirect not working? |
+50That's becausemime_content_typeisnot affectedby.htaccess. However, the documentationspecifiesthat you can setmagic.mimefile:string mime_content_type ( string $filename )Returns the MIME content
type for a file as determined by using information from themagic.mimefile.There is alsofinfo_open(PECL) function that has$magic_fileas a parameter. | Why PHP method$mime = mime_content_type($filename);givesmime-type = application/zipfor apk files?? I've defined apk mimetype in htaccess.htaccess<IfModule mod_mime.c>
AddType application/vnd.android.package-archive apk
AddType application/apk apk
AddType application/java-archive jar
</Ifmodule>
<FilesMatch \.apk$>
SetHandler application/vnd.android.package-archive
</FilesMatch>I've tried all the solutions provided below but still none of them solved the problem. Need help regarding this. | PHP Mime Type for apk files |
Have it this way inside/testing_url_document/.htaccess:RewriteEngine On
RewriteBase /testing_url_document/
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^./]+)(/.*)?$ $1.php$2 [L]
RewriteRule ^([\w-]+(?:\.php)?)/([\w-]+)/([\w-]+)/?$ $1?$2=$3 [L,QSA,NC] | I've spent a couple of hours trying to achieve something I thought was easy. I havehttp://localhost/testing_url_document/second.php?id=2and want to turn ithttp://localhost/testing_url_document/second/id/2. I have achieved to remove the php extension but stucked into the rewriting the site page . In the htacces i have followed the following procedure.RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]this is my index pageIndex.php<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
// put your code here
?>
<a href="second/id/2">click here</a>
</body>
</html>Second.php<?php
echo $_GET['id'];
?>The second.php should gets the value 2Thanks in advance for help. | Rewrite url to remove question mark and add slashes in htaccess |
You can use this rule in root .htaccess ofbetasubdomain:RewriteEngine On
RewriteCond %{HTTP_HOST} =beta.example.com
RewriteRule ^(images/.+)$ http://example.com//public/$1 [L,NC,R=301] | I have a webserver and a subdomain. All of my images are stored in /public/images within my site directory for www.mysite.com. However I have a separate site directory for testing beta.mysite.com however on this page with a different git branch all of my images are broken because I did not want to copy all of the images. Is it possible to say for all image requests or for all 404 requests try looking at mysite.com?I have found an example on another questionsRewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteRule ^images/(.*)$ http://example.com/sub_ds/test/images/$1But since I am rather new to mod_rewrite im not sure what is going on or how to manipulate it to work for me. | Apache Rewrite for images on subdomain |
I prefere to move all your php files in a other directory and put only 1 php file in your htdocs path, which handle all requests. Other files, which you want to pass without php, you can place in that folder too with this htaccess:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$0 [L]Existing Files (JPGs,JS or what ever) are still reachable without PHP. Thats the most flexible way to realize it.Example:- /scripts/ # Your PHP Files
- /htdocs/index.php # HTTP reachable Path
- /htdocs/images/test.jpg # reachable without PHP
- /private_files/images/test.jpg # only reachable over a PHP script | After many hours messing with .htaccess I've arrived to the conclusion of sending any request to a single PHP script that would handle:Generation of html (whatever the way, includes or dynamic)301 Redirections with a lot more flexibility in the logic (for a dumb .htaccess-eer)404 errors finally if the request makes no sense.leaving in .htaccess the minimal functionality.After some tests it seems quite feasible and from my point of view more preferable. So much that I wonder what's wrong or can go wrong with this approach?Server performance?In terms of SEO I don't see any issue as the procedure would be "transparent" to the bots.The redirector.php would expect a query string consisting on the actual request.
What would be the .htaccess code to send everything there? | Redirect any GET request to a single php script |
You don't need a blanket redirect in .htaccess or in PHP. Go to Dashboard >> Settings and change your URLs to https. Then save permalinks.You may want to find/replace any http URLs in post/page content, media URLs, etc, so you don't get redirects for those from http to https. Tryinterconnectit.com WordPress Serialized PHP Search Replace ToolAfter https is working, useFirebugwith Firefox, or use the developer tools inChromeorSafariorIEto see if you are getting any "insecure content" errors from non-https URLs in any theme files.You may need to change to a relative path for images in CSS files, i.e.background-image: url(http://example.com/themes/wp-content/theme/images/image.jpg)tobackground-image: url(images/image.jpg)And, you may need to remove thehttpfrom absolute paths in php theme files, i.e. change'http://example.com/image.jpg'to'//example.com/image.jpg'; that will allow your resources to default to https. | I'm trying to get a wordpress site to HTTPS, but everything I try gives me a redirect loop. I've edited the htaccess, I've set it in PHP, I've even downloaded a wordpress plugin to convert it, but every method gives me a redirect loop error. I know that something has to be redirecting my https to http, but I don't know what. Here is my .htaccess file without any of the HTTPS settings in it:# 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 WordPressAnd here's the PHP I'm trying to use in the header php file to conver the page to HTTPS:if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
} | Convert a full wordpress site to HTTPS |
You can't use a<location>container in an htaccess file. It's probably best to put this in your apache server config file next to yourProxyPasssettings:<LocationMatch "/photo">
# Image Proxy
ProxyPass http://photo.licensor.com
ProxyPassReverse http://photo.licensor.com
Header unset Etag
Header set Cache-Control "max-age=86400, public"
Header unset Expires
</LocationMatch> | We proxy images as licensed content andneed to add max-age headers to the proxied images. Attempted modifying.htaccess, but it didn't work and suspect this is due to the proxied image folder not being an actual directory on the server.First, the proxy is set up inapache2.conf:# Image Proxy
ProxyPass /photo http://photo.licensor.com
ProxyPassReverse /photo http://photo.licensor.comMade several attempts to modify.htaccessunder the site's public_html directory. It appears that the condition to modify the max-age header for proxied images is never recognized by Apache since/photois not a real directory.I'd really like to target ONLY the proxied images using the/photodirectory that isn't real. | How can proxied image headers be modified on Apache? |
following command works for me Great !sudo a2enmod rewrite
sudo service apache2 restartTo check loaded modulessudo apache2ctl -M | I have an instance running ubuntu in ec2. I have this .htaccess file :-Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.phpThis file is located inside thevar/www/htmlfolder. I am aiming to achieve loading ofamazon-public-dns.com/index.phpasamazon-public-dns.com/index.Now, I have tried these steps :-1)
Creating therewrite.confin/etc/apache2/mods-enabledand in the file putting the lineLoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so. (Refer this answer)2)
Running the commandapache2 enable module rewrite. Also, in the file/etc/apache2/sites-available/000-default.confand writing this in the end :-<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
# changed from None to FileInfo
AllowOverride All
Order allow,deny
allow from all
</Directory>Note thatthis answertold to edit thedefault. But, since that file was not there in my case, I edited the000-default.conffile.I restarted apache as told. But the linkamazon-public-dns.com/indexgives me a 404 :( Please help me.EDIT: I put some random junk in the htaccess file. But the index.php is not giving any 500 internal server error which means that the htaccess file is being ignored. Now inhttps://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles, they say to enable htaccess edit this file -/etc/apache2/sites-available/default.BUT THERE IS NO SUCH FILE | How to enable .htaccess in amazon ec2 running ubuntu |
No, the order of flags in a single RewriteRule does not matter. | I could not find documentation that says the order of the flags in RewriteRule matter. I don't think it does, but would like to get confirmation.Are these two equivalent?RewriteRule ^/test(.*) https://example.com/sites/test$1 [NC,R,L,NE]
RewriteRule ^/test(.*) https://example.com/sites/test$1 [NC,NE,R,L] | Does the order of RewriteRule flags matter? |
This simple .htaccess will remove your index.phpRewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]Change your check function like thispublic function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
//may be you need to set login credential into session
redirect('Phonebook/home/');
//$this->load->view('home');
}else{
$this->load->view('login');
}
}and your home function will be like thispublic function home(){
//remember you need to check login validation from session
$this->load->view('home');
}to useredirectfunction remember you haveurlhelper loaded.May be this help you | I am trying to use.htaccesson CodeIgniter, but it is not working.I have already set:AllowOverride All$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';I am using XAMPP on Windows.My.htaccess:RewriteEngine On
RewriteCond $1 !^(index\.php|images|scripts|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]My URL still containsindex.phpand, if I try to remove it manually, it returns a 404 errorAlso my other concern is my login page: whenever I login, my URL is stuck on the check page.I was wondering how do I rewrite my URL to change to home page instead of staying on the check page.public function check(){
$this->load->model('check');
$logcheck = $this->check->check($this->input->post('username'),$this->input->post('password'));
if($logcheck == "admin"){
$this->load->view('home');
}else{
$this->load->view('login');
}
} | Codeigniter Htaccess and URL Redirect issues |
Just to be sure: you wanthttp://example.org/site/foo/bar/baz.phpto go tohttp://example.org/foo/bar/baz.php, that is, to remove (via redirect) the /site prefix if it's there, but not touch the URL otherwise, right? If so, it depends on which server you're using:If your server is Apache, you could use something like this in.htaccess:RedirectMatch 301 ^/site/(.*)$ http://example.com/$1If it is nginx, add this to theserver {...}session of your site's file (usually symlinked inside/etc/nginx/sites-enabled):location ~ ^/site/(.*)$ { rewrite ^/site/(.*)$ /$1 permanent; }Here is a good explanationon how such pattern-based redirects can be set up in both servers. | I am struggling with an age old problem. I inherited a site with some pretty good SEO and one glaring problem. The entire site is hosted on the /site/ subdirectory. I have decided that I need to load the site at the root. So something likehttp://example.org/site/index.phpwill instead redirect to /index.php (<-- that counted as a link, if it is unclear I mean it to be the root of the site/index.php.)We use joomla for our backend and there are hundreds of pages on the site at this point. I have struggled getting any of the redirects I have seen to do what I want them to do. Basically, any page our patrons visit from an old link with/site/in it should be redirected to the exact same link, but without the star.I am open to just loading the page from /site/ and making it look like it is from root. It is my understanding that this can be done with some advances mod-rewrite (http://kb.mediatemple.net/questions/85/Using+.htaccess+rewrite+rules#gs?) but I have not had any success yet. I run a beta site that mimics the parent site in a subdomain that I have already moved from /site/ to / so I can test a lot of .htaccess configs.Any help is appreciated... thanks! | Advanced 301 redirect for an entire site at site root? |
Replace your current code by this oneOptions -Indexes +FollowSymLinks
RewriteEngine On
# redirect "www" domain to https://example.com
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# redirect http to https (at this point, domain is without "www")
RewriteCond %{HTTPS} =off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] | I have a problem with .htaccessI have a certificate in my server, and it's only forhttps://example.com(nothttps://www.example.com) Therefore, I'm trying to do a .htaccess redirect to the correct url.My intention is this:http://www.example.com --> https://example.com
http://example.com --> https://example.com
https://www.example.com --> https://example.comI tried different combinations and nothing seems to work. At the moment I have this, but seems like is not working forhttp://www.example.com/subfolder, I don't know what is failing...RewriteEngine On
# Follow symbolic links.
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# Prevent directory listings
Options All -Indexes | Redirect to https using .htaccess |
Here's what I've been using:SetEnvIf User-Agent ^Amazon Cloudfront$ cdn
SetEnvIf Host ^static.dev.website.com$ cdn # This could also be a cloudfront.net host
AuthType Basic
AuthName "Dev Site"
AuthUserFile /directory/location/.htpasswd
Require valid-user
Order Deny,Allow
Deny from all
Allow from env=cdn
Satisfy AnyEssentially, you need you exclude CloudFront-related requests, which the first two lines handle, in conjunction with theAllow from env=cdnline. | I'm testing out Amazon Cloudfront in our dev environment, which is protected by .htaccess/.htpasswd. The password protection on the dev server is causing all of the cloudfront.net assets to be password protected as well. And no username/password combination works.What I need to do is allow cloudfront to access the dev server by poking some holes in the .htaccess protection.I can get a list ofIP addresses herebut since they are subject to change, I was wondering if anyone knew of a better way.I cannot remove the password protection unfortunately. | Amazon Cloudfront and .htaccess |
You need to have mod_headers installed, or you might get error 500. You can wrap the setting of headers in a condition to check if mod_headers is present or not.<FilesMatch "\.(html|htm|js|css)$">
<ifModule mod_headers.c>
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Thu, 1 Jan 2015 05:00:00 GMT"
</ifModule>
</FilesMatch>You can also unset headers. For example, if you're behind a load balacer the real visitor IP could be passed in form of a custom header you don't want to expose to the application.Header unset Real-Visitor-IPBesides expiration and etags, and webserver specific custom headers, you shouldn't tamper with headers at webserver level. Most of them should be managed at the application level, and you would prevent some frameworks from working normally if you pass them altered content types. | So I have these headers in some of my PHP files:<?php
header('Content-Type: text/html; charset=UTF-8');
header('Content-Style-Type: text/css');
header('Content-Script-Type: application/javascript');
header('HTTP/1.1 200 OK');
header('Content-language: en-US');
header('X-Powered-By: PHP/5.2.17');
header('Last-Modified: Tue, 01 Jan 2013 00:00:00 GMT');
header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate');
header('Pragma: no-store, no-cache, max-age=0, must-revalidate');
header('Expires: Tue, 01 Jan 2013 00:00:00 GMT');
?>How do I set them in my .htaccess file? (Should be for specific files only), here's what I got so far:<FilesMatch "^(index.php|about.php|contact.php)$">
# HTTP Headers should be set in here
</FilesMatch> | How to set some PHP headers in a .htaccess file |
Try this in your.htaccess<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?$1 [QSA,L]
</IfModule>Location of files should be:/silex/.htaccess
/silex/web/index.php | My .htaccess:<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /silex/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>Index.php:<?php
ini_set('display_errors', 1);
require_once __DIR__.'../vendor/autoload.php';
$app = new Silex\Application();
$app->get('/hello/{name}', function ($name) use ($app) {
return 'Hello '.$app->escape($name);
});
$app->run();I got this error when accessing localhost/silex/hello/world:"Sorry, the page you are looking for could not be found."why? | Sorry, the page you are looking for could not be found. silex error |
I think of git as mainly a tracker for software components (such as lines of code) and not software configuration.A server password is configuration and therefore to be excluded from change control. The .htaccess file is a configuration artefact necessary (As I understand it in your case) for the correct operation of your application, and therefore subject to change control via git.The way I see it you have two options. It strikes me as more elegant to move the configuration out of the repo, but if you have to keep it in the .htaccess file you can usesmudge/clean scripts in .gitattributes. Smudge/clean filters inject defined changes into tracked content upon checkout (i.e. injecting passwords) and clean the password out of the tracked content again upon staging (i.e. substitute the password with a generic foobar).Bear in mind, since these smudge/clean filters are defined in the git config they do not get passed around the way otherwise tracked files do, so you need to keep track yourself that the right filters are in place where they should be.In either case, whether you keep the configuration out of the repo or do manual smudge/filter management across instances of the repo, you'd benefit from having ause protocolfor git which would (amongst other things) state how you handle configuration and state rules for which smudge/clean scripts go where and/or where server configuration lives. | Another developer says we should put .htaccess files in the git repo, but because the live server uses passwords and our local boxes don't, I said we should put them in the .gitignore. However, he says that if you have to have different .htaccess files across instances, you're doing it wrong. I argue not all server instances are going to be the same, and sometimes (if not often) they require their own configurations. He agreed that we could simply create a "htaccess" file in repo that is copied to .htaccess on live, but still preferred doing it his way. To me, things like server config should be kept out of repo. Also I'm not sure I need to change my development OS just to match a live server exactly or run VM software. Am I missing something here? Which is the best way, or what's a better alternative? | What is the best way to handle .htaccess with a git repo? |
Check your Apache config file (httpd.conf) and make sure the directory you are using for your site includes the AllowOverride option.Example:<Directory "/Applications/MAMP/htdocs">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory> | I have the file structureindex.php
.htaccess
news/index.php
news/.htaccessFirst .htaccess:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/news/
RewriteRule . /index.php [L]Second (news/.htaccess)RewriteEngine On
RewriteRule . /index.phpRequesthttp://test.t/news/news/61the handles first index.php but I need to do it the secondI tried a few more options for the first .htaccess, but it did not succeed | Rewrite rule for subfolder |
RewriteCondconditions only apply to theRewriteRulethat immediately follows the condition(s). Your last 2 rules don't have any conditions on them and the rules are looping. Just add the 2 conditions in front of the last 2 rules:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA] | I am using the following .htaccess code:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ca/(.+)$ /index.php?p=$1&c=ca [L,QSA]
RewriteRule ^fr/(.+)$ /index.php?p=$1&c=fr [L,QSA]
RewriteRule ^(.+)$ /index.php?p=$1 [L,QSA]In order to achieve the following effect:http://xyz.com/ca/test -> http://xyz.com/index.php?p=test&c=ca
http://xyz.com/fr/test -> http://xyz.com/index.php?p=test&c=fr
http://xyz.com/test -> http://xyz.com/index.php?p=testBut it is failing with a server error. Any ideas on how to fix it?Thanks | .htaccess RewriteRule country codes and urls |
If you want to make sure your site works well with HTTPS, turn off plain HTTP (assuming it's for whole server), or use Apache Httpd directives (in.htaccessor in the main configuration) that make the pages that need to be served over HTTPS return an error (e.g. 404) when they're accessed over plain HTTP.
You could achieve this for a specific IP address by usingDeny from xxxxxxx.Don't rely onmod_rewriteor similar to redirect plain HTTP requests to their HTTPS equivalent. This will at best hide problems and cause a false sense of security.The reason for this is that, even with a redirect, the initial requests are made in clear before being redirected: make sure all the references usehttps://URIs before making use of them. You can find more details inthis answer. | Here are some questions I have about SSL.RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} somefolder
RewriteRule ^(.*)$ https://www.domain.com/somefolder/$1 [R,L]Above is code to force everything to go to SSL via HTAccess. Is there a way I can restrict this code to a specific IP Address. I want to force SSL for just my IP address so that I can test the site thoroughly using the new SSL links, and see (make sure)
everything is working before taking it live to the live site. Testing with just my IP would be a lot easier.Is SSL going to interfere with any get/posts? Meaning...if I use that code above, and someone is on a page..and they submit a form, it's going to force them into SSL, is that going to be considered a redirect
and clear out any post/get variables? I just want to try to find out ahead of time if it's going to mess up anything I have running.Have any of you had any situations where you forced SSL then had a lot of issues with the site not working right? | Forcing SSL via HTaccess |
I'd say to configure your Apache to point all yourvirtual hoststo the same folder, then use$_SERVER["SERVER_NAME"]to figure out what subdomain was requested. | I have a multilingual (11 languages) website. Right now it works chooses language using 'language' get parameter or a cookie. Now I want to use subdomains instead of cookies and get parameter. But I do not want to make 11 complete copies of website (engine and some static stuff) for each subdomain. Is it possible to place some php and htaccess code (a very little piece) into each subdomain's root catalog, so only one copy of website's engine and stuff will be used by 11 subdomains. Thanks. | PHP: multilingual website on subdomains w/o many copies of public_html |
You can use a RewriteMaphttp://httpd.apache.org/docs/2.3/rewrite/rewritemap.htmlLet's say your map file looks like this and is called moved.map:-/about profile
/page/that/has/moved new/locationYou .htaccess would need something like this:-RewriteMap moved txt:moved.map
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond ${moved:%1|NOT_PRESENT} !NOT_PRESENT [NC]
RewriteRule .? ${moved:%1} [NC,R=301]This will redirect with a 301 status codehttp://your.domain.com/abouttohttp://your.domain.com/profileand redirecthttp://your.domain.com/page/that/has/movedtohttp://your.domain.com/new/locationYou can then programmatically create moved.map.I hope that helps. | My main htaccess file does a bunch of things for my site to function correctly.
I have added redirects for pages that have moved. I don't have root access to the server and using .htaccess is my only option.Is it possible to include separate files for the redirects in the .htaccess file so I can keep them separate and write programatically to the additional files that hold my redirects?Basically I want to reference separate files from my .htaccess to manage rules dynamically and also neaten up one long .htaccess file with a few smaller files.I also want to add redirect rules on the fly as things change on the site within my application. | Can one include separate files in htaccess for a list of redirects? |
you can do:$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; //you can also leave blank this CI tend to find this by himself
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; //if not working try one of these:
'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFOand try this.htaccessi use for many sitesRewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]if not working yet, use aphpinfo();and check if mod_rewrite isenabled | my codeigniter work perfectly on local host but not work at live.my codeigniter is latest version.i also try older.it always show me page not found on redirect.routes.php setting is$route['default_controller'] = "home";
$route['404_override'] = '';i also upload htaccess on server.i tried in linux and window both.htaccessRewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] | codeigniter not work at live page not found error on server |
I verified that the following script works on our current hosting plans:RewriteEngine on
rewritecond %{http_host} ^coolexample.com [nc]
rewriterule ^(.*)$http://www.coolexample.com/$1 [r=301,nc]There is a possibility that you are on an older version of our hosting plans. If that is the case, you may want to consider upgrading. Check outhttp://x.co/Zecqfor a how-to on upgrading. There is also a link to the 4GH FAQ. Please review that before upgrading to avoid unwanted surprises. | This htaccess works fine locally, but on GoDaddy the URL isn't caught by the rewrite engine.RewriteEngine on
RewriteRule ^products/amsoil/(.*)/$ /products.php?amsoil=$1 [L]
RewriteCond %{HTTP_HOST} ^somedomain.com
RewriteRule (.*) http://www.somedomain.com/$1 [R=301,L]This worked until a few days ago. Basicallywww.somedomain.com/products/amsoil/this-product/should forward towww.somedomain.com/products.php?amsoil=this-product....did work, and still works locally however now I just get a 404 error onwww.somedomain.com/products/amsoil/this-product/Any ideas? | Quick mod_rewrite help on GoDaddy |
Try this in your .htaccess file:Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L]
# for https
RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^(.*)$ https://www.domainB.com/$1 [R=301,L]This will preserve your URI while redirecting from domainA to domainB. | I'm now migrating my website to a new host and domain, and I want to know if I can redirect anyone who enters any URL of the old website to the new website, while keeping all of the URL parameters. for example:When somebody types in this urlhttp://www.domainA.com/blog/?p=667, I want him to be redirected tohttp://www.domainB.com/blog/?p=667.Is there any way I can do that by adding some .htaccess configurations?Thanks! | How to redirect a URL by only changing the domain name, while keeping other URL parameters |
After messing around a bit with vbence's answer, I stumbled upon a more functional solution, although I'm not sure if it's the most optimised one.<IfModule mod_rewrite.c>
RewriteEngine On
# Requests for "/res/all.20110101.css" serve up "/res/all.css", etc.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)\.([0-9]+)\.([a-z]+)$ $1.$3 [L]
# If the hostname isn't www.domain.com AND requested file's extension
# isn't in the filter list, redirect to the www.domain.com version.
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !\.(js|css|png|jpe?g|gif)$ [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
</IfModule> | I've set up a couple of "domain aliases" for a website which I'm using as cookie-less sub-domains, sostatic.domain.com/style.cssserves the same file aswww.domain.com/style.css.However, if someone tries to accessstatic.domain.com/index.htmthey should be 301 redirected towww.domain.com/index.htm. Themod_rewriterules I have in the root web directory I thought would work but they don't seem to be.<IfModule mod_rewrite.c>
RewriteEngine On
# "/res/all.20110101.css" => "/res/all.css"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ $1.$3 [L]
# Except for "static" sub-domains, force "www" when accessed without
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^s-img\.domain\.com [NC]
RewriteCond %{HTTP_HOST} !^static\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
# If file requested is HTML, force "www"
<FilesMatch "\.(htm|html|php)$">
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
</FilesMatch>
</IfModule> | Restrict "static" sub-domain aliases to non-HTML files, otherwise redirect to "www" |
It is Apache and FF bug,https://issues.apache.org/bugzilla/show_bug.cgi?id=35256Hopefully it'll be fixed in soon feature.AllowEncodedSlashes should really be "on" by default and probably even deprecated. ...Nowhere the RFCs is a backslash(\)listed as a reserved character. Therefore a%5Cshouldalways be decoded the same as%7Eis converted to a tilde(~).To solve it on Apache:addAllowEncodedSlashes OninVirtualHosthttpd-vhosts.conf or httpd.conf, and .htaccess:RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)\\(.*)$
RewriteRule .* %1/%2 [R=301,NC,L] | How to rewrite backslash'\'with slash'/'on Firefox?Chrome, IE, Safari, Opera has build browser rewrite backslash with slash.But Firefox 3.6.13 returns404 error page.# Why Firefox returns 404 error page?
RewriteCond %{REQUEST_URI} (.*)\\(.*)
RewriteRule .* %1/%2 [R=301,L] | Apache .htaccess: How to rewrite backslash with slash on Firefox? |
You can edit your local httpd.conf file, and add the mime modules you need:<IfModule mime_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php .html
AddType application/x-httpd-php .htm
AddType application/x-httpd-php .txt
</IfModule>This should work for your local host. If you can't configure your server this way, and since your .htaccess works there, use the .htaccess config for your server only. | I am using this snippet in my .htaccess file to parse html as php:<FilesMatch "\.(html|htm|txt)$">
SetHandler application/x-httpd-php5
</FilesMatch>this is working fine in my website(online) but not in my localhost (using WAMP latest version)..
but if I change the above code to:<FilesMatch "\.(html|htm|txt)$">
SetHandler application/x-httpd-php
</FilesMatch>then, this is working fine in my localhost but not in my website..
I have to add/remove the5inSetHandler application/x-httpd-phpto work in either one side.Please, help me.. | html not parsing as php in wamp |
For those finding this post later I worked out my own solution.
Seems when the alex toolbar is installed it shows up in the user agent.<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>You can redirect those users with phppreg_match('/(Alexa)/i',$_SERVER['HTTP_USER_AGENT'])?header('Location: http://alexausersgohere.com'):null;You could also just redirect them by dumping this in your .htaccess file.Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^Alexa
RewriteRule ^(.*)$ alexausersgohere.com#$1 [R=301,L]Make sure you double check that htaccess code I just wrote it as a demonstration, its un-tested I used php. | Any ideas how I can block Alexa Toolbar users? I don't want to appear in the rankings while we are in beta ...I see you can block their search engine withUser-agent: ia_archiver
Disallow: /but I can't find any documentation on how to pull your self from actually being ranked..
I read earlier someone tried to email them and they rufused.. So I guess I'm forced to block them?Any better ideas, or way ideas on how to block them access? | How can I block Alexa Toolbar users? |
Try this:RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301] | I have an SSL certificate for the 'www' subdomain of a web site we'll call example.com.Therefore I can force SSL, but if the user doesn't enter 'www.example.com' into their browser, the SSL certificate appears invalid.I wish to accomplish this with mod_rewrite rules in an .htaccess file at the root of the web site.No matter what URI the user enters, (e.g. example.com, www.example.com,https://example.com, example.com/folder/file.html, etc.), I want to force the HTTPSandthe www subdomain, keeping whatever URI they provided, of course.I was playing around with the .htaccess file and some rules, as I've already done some research, but I don't have much experience with mod_rewrite or .htaccess. I think I found the SVN revision thatalmostworked for me, but not quite. Here it is:RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^example.com [nc]
RewriteRule ^(.*)$ https://www.example.com/$1 [r=301,nc]Try not to laugh too hard at my file; it is mostly derived from examples I found online.Any pointers are appreciated! =) | Forcing SSL & www subdomain for any URI entered with .htaccess? |
It is generally a case of just going through one by one and converting them. I don't know of any automated means,The docs -http://redmine.lighttpd.net/projects/1/wiki/Docs:ModRewrite- has the regexes available, and some examples.if there are any particularly problematical items, I'd edit the question to show them, and ask for the answers here. | It's big problem to convert mod_rewrite rules to lighttpd format | How to convert Apache .htaccess files into Lighttpd rules? |
+50To modify the .htaccess you would need to add something like this to your .htaccess This will redirect all request from /admin to /public but still show as /admin which will allow your redirect inweb.phpto work:-RewriteRule admin /public [L]Which would give you:-<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule admin /public [L]
RewriteRule ^ index.php [L]
</IfModule>However I still feel that this is bad practice, and changing your directory strcture as @flakerimi sugested would be a much better solution. | I create virtual host for my project in local xampp. Url:http://kooltech-us.com/I have folder's name admin (From picture below ) in public folder (Laravel) .in my project my admin login urlhttp://localhost/admin/login.I hit urlhttp://localhost/admin/loginto go to admin login page .. it's okay..
but when i hit thishttp://localhost/admin. it takes me to the public/admin folder . That means show me public Directory listing.For prevent access Directory listing or public/admin I write inOptions - Indexescode in .htaccess file .it's give me 403 Error ( Access forbidden! ) in general. it's work.I looking for that when I hit the urlhttp://localhost/adminit will take me tohttp://localhost/admin/login.Note:I did not change folder structure. (Laravel Default Folder Structure Exist).Only one line code I write in .htacees file :Options - Indexes. that give me 403 Error ( Access forbidden! ) in general.Version "laravel/framework": "5.8.*"I write in web.php but it's not working ..Route::get('/admin', function () {
return redirect('/admin/login');
});if need more explanation please comment.. | Redirect Url Issue with Laravel and htaccess |
+50Your rule redirecting everything tohttps://www.domain.tld/because of your last rule, and for redirecting enbloc you can use regular expression for match try with below,RewriteEngine On
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.+)$ https://www.domain.tld/$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ https://www.domain.tld/$1/ [R=301,L]If there are other certain patterns please provide them and I am assuming you are using the rules in root.htaccessor respective directory. | I am looking for quite some time here to find something similar, but I am unable to find what I am looking for.I would like to redirect an old Project discarded Project to a new one, they are only partly similar and I would like to redirect the matches, and afterwards everything else, while removing everyI think I remembere that htaccess Rules are worked one after another, so I can simply add 301's above the redirect everything else, but it turns out that this codeRewriteEngine On
Redirect 301 /match1.html https://www.domain.tld/match1/
Redirect 301 /match2.html https://www.domain.tld/match2/
Redirect 301 /match3.php&page=6 https://www.domain.tld/match3/?
RewriteBase /
RewriteRule .*? https://www.domain.tld/? [R=301,L]redirects simply everything directly tohttps://www.domain.tld/The Old Project mas completely manual work with 450+ static html pages and another ~100 php files, so I hope there is a more simple way that creating a huge .htaccess to do this. | redirect everything with exceptions |
For your required url you can use below rule in root directory it is for rewriting,RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/$ php/$1.php [L] | I'm trying to shorten my URL but sadly can't find anything that helps.I divide my code in folders. Index is positioned at root just like my .htaccess.
The folders are named like the file extensions, so php, js, css [...]I have a link like the following:localhost/php/getBets.phpand want it to belocalhost/getBets/I already have the part that cut's the .php extension at the end, so here is my full .htaccesOptions +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Hide Index
IndexIgnore *
# Forbid accessing certain sites
RedirectMatch 403 ^/.gitignore$
RedirectMatch 403 ^/.htaccess$
RewriteRule ^(?!index)(?!.*getBets).*\.(php|rb|py|txt|md|sql|inc)$ - [F,L,NC]
# Hide .php file ending in URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]Can someone maybe tell me how I could achieve this? :)
Thanks alot! | Cut folder path from URL via .htaccess |
InUrlManagerthere arerules, you can define your own rules.
your UrlManager may look like this.'urlManager' => array(
'urlFormat' => 'path',
'rules' => array(
'gii' => 'gii/index',
'gii/<controller:\w+>/<action:[\w-]+>' => 'gii/<controller>/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'site/lesson/<act:\w+>/<id:\d+>' => 'site/lesson'
//This will callactionLessoninSiteController, which is supposed to get two parameter .You method should look something like this.public function actionLesson($act,$id){
//
} | I have url like this:www.studyenglish/index.php?r=site/lesson&act=read&id=1I would like change to be:www.studyenglish/site/lesson/readI have added this script in url manager config/main.php'urlManager'=>array(
....
'showScriptName'=>false,
....
),and add this script in .htaccessOptions +FollowSymLinks
RewriteEngine on
RewriteBase /
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.phpBut it only work in url like this:www.studyenglish/index.php?r=site/lessonto be:www.studyenglish/site/lessonSo, how to change this urlwww.studyenglish/index.php?r=site/lesson&act=read&id=1to bewww.studyenglish/site/lesson/readHopefully someone can help.
Thanks ... | Url manager and Htaccess in Yii1 |
I did it. It works with these lines. Thanks to everyone :)Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(bg|en)/post/([^/\.]+)$ blog_post.php?lang=$1&id=$2 [L]
RewriteRule ^(bg|en)/(.*)$ $2?lang=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L] | I have a multilanguage website. I want the URL's to be like:http://example.com/en/blog_post/2whereblog_postis the name of the fileblog_post.phpand2is value of the parameter id.I have this .htaccess code nowOptions +FollowSymLinks
RewriteEngine On
RewriteRule ^(bg|en)/(.*)$ /$2?lang=$1 [L]
RewriteRule ^(bg|en)/(.*)/([^/.]+)$ /$2?lang=$1&id=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]I tried with this line, but it doesn't work:RewriteRule ^(bg|en)/(.*)/([^/\.]+)$ /$2?lang=$1&id=$3 [L]Can you help me please :) | Multilanguage and mod_rewrite |
You can use yourusershiding rule just below redirect rule:DirectorySlash Off
RewriteEngine On
# Rewrites the requested http to https.
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
# add a trailing slash to directories
RewriteCond %{DOCUMENT_ROOT}/users/$1/ -d
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302,NE]
RewriteCond %{THE_REQUEST} /users/(\S*)\s [NC]
RewriteRule ^ /%1 [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?((?!users/).*)$ users/$1 [L,NC]
# Hide GET variables link.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^posts/(.*) posts.php?p=$1 [L,QSA]But just keep in mind it will forward everything to/users/thus making your last rule defunct. | I'm trying to hide a directoryusersof url (ex.:):meusite.com.br/users/testebut so far not succeeded. Like that by accessingmeusite.com.br/testeshow the content inside the foldertesteand, if accessed URLmeusite.com.br/users/testethe/users/were removed and only exhibited themeusite.com.br/teste.I've tried:RewriteCond %{REQUEST_URI} !^/users
RewriteRule (.*) /users/$1 [QSA,L]but I did not succeed. I also tried:RewriteCond %{REQUEST_URI} !^/users
RewriteRule ^/?([^/]+)$ /users/$1 [L]but not worked.For a better understanding, it follows part of the structure of the site folders:├── users
| ├── teste
| | └── index.html
| └── outroteste
| └── index.html
├── .htaccess
└── index.phpAs my file 'htaccess` is already:<IfModule mod_rewrite.c>
RewriteEngine On
# Rewrites the requested http to https.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# Hide GET variables link.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^posts/(.*) posts.php?p=$1
</IfModule>I hope you can help. | Hide a directory with htaccess |
You can't use a[R=301]and expect the URL not to change. R means redirect. So it will change to the URL you told it to. For an internal rewrite you need to leave that off.If you have .htaccess in your document root then you should be able to do this. I don't know how your setup is but this should rewrite the URI.Options -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^app/index.php/appmedia/default/login/?$ /app/index.php/zurmo/default/login [L]If you are usingyii frameworkdo like this:'urlManager' => array (
'class' => 'application.core.components.ZurmoUrlManager',
'urlFormat' => 'path',
'caseSensitive' => true,
'showScriptName' => true,
'rules' => array(
// Begin Not Coding Standard
// API REST patterns
array('zurmo/default/login','pattern' => 'appmedia/default/login', | I want to rewrite some url by using.htaccessrewriteI have url something like this:domain.com/app/index.php/appmedia/default/loginand want to rewrite users todomain.com/app/index.php/zurmo/default/loginSo, what will happen is users will see appmedia in browser but in the backend it will access zurmoI'm new to php and have read some blogs likethishave no luckAlso, have tried thisRewriteEngine On
RewriteRule ^app/index.php/appmedia/default/login.*$ http://domain.com/app/index.php/zurmo/default/login [R=301,L]it says The page isn't redirecting properlyEdit of .htaccess fileRewriteEngine On
RewriteRule ^app/index.php/appmedia/default/login.*$ http://mydomainx.com/app/index.php/zurmo/default/login [R=301,L] | Php rewrite url through .htaccess |
If you're concerned PHP isn't picking up the right value from your php.ini, you can useini_getto check it.If your concern is that PHP is just compressing regardless you can just make an HTTP request by hand (using netcat, telnet, etc.) or snoop on your a request for your browser using the developer tools. Just make sure request headers includeAccept-encoding: gzip, deflateand check theContent-encodingresponse header. However, keep in mind that there could be other offenders here (like mod_deflate, your PHP script, a proxy…). | I addedphp_flag zlib.output_compression offto my .htaccess. I read PHP compression needs to be disabled if I want to get mod_deflate working.Is there any way to test whether PHP compression is really disabled? | zlib.output_compression off - How to test whether PHP compression is really disabled? |
You can create a button/href link with this URL:<a href="/?desktop=1">Full Desktop Site</a>And then change your rewrite as this:RewriteEngine On
RewriteCond %{QUERY_STRING} !(^|&)desktop=1(&|$) [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://m.example.com/ [L,R=302] | I currently an redirecting to a mobile site based through htaccess as follows:RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|googlebot-mobile|iemobile|ipad|iphone|ipod|opera mobile|palmos|webos" [NC]
RewriteRule ^$ http://m.example.com/ [L,R=302]Is there someway to have a full site button on my mobile version that will ignore this rule if clicked? I don't want to use javascript to do my redirect and check for full site...I'm okay with the idea of php doing it though, but I know htaccess gets knocked off before php rules. | Is there a way to have a full site button on a mobile app without javascript? |
You're doing it upside down.Put this code in your htaccessRewriteEngine On
RewriteBase /
RewriteRule ^old([0-9]+)$ image.php?$1 [L]
RewriteRule ^admin/(.*)$ ninja-admin/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]The rule for your images is the followingRewriteRule ^old([0-9]+)$ image.php?$1 [L]It will forward every url like/old123(where123is one or more digits) toimage.php?123EDIT: if you want to forbid direct access toimage.php?xxxthen you can do it this wayRewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/image\.php\?([0-9]+) [NC]
RewriteRule ^ old%1 [R=301,L]
RewriteRule ^old([0-9]+)$ image.php?$1 [L]
RewriteRule ^admin/(.*)$ ninja-admin/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L] | I have old site with links like this:http://domain.com/image.php?690And I would like to change it into:http://domain.com/old690I have tried many different Rules, fe.:RewriteRule ^image.php?(.+) old$1 [L]EDIT: All rules looks like:RewriteEngine OnRewriteRule ^admin/(.*) ninja-admin/$1 [L]RewriteRule ^index.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . index.php [L]RewriteRule ^image.php\?(.+) old$1 [L]What is correct RewriteRule, and why? | Mod Rewrite file.php? to string |
This should changehttp://www.mysite.com/subfolder/tohttp://www.mysite.com/RewriteEngine On
RewriteRule ^/subfolder/(.*)$ http://www.mysite.com/$1 [L,R=301] | I've moved WordPress into it's own directory as per the instruction found on the WordPress support site.I've got his working fine but the URL now showshttp://www.example.com/subfolder/but I want it to show without the/subfolder/I can't seem to get the htaccess to remove the/subfolder/Here's my current htaccess codeRewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?mysite.com$
RewriteRule ^(/)?$ subfolder [L] | Remove subfolder from WordPress URL using htaccess |
Have your rule like this:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
</IfModule> | My website is v2.example.com and I am trying to write a .htaccess rule but unable.I want this : v2.example.com/ABCDEFGHAnd I want to get the value ABCDEFGH as a parameter like it is v2.example.com/index.php?id=ABCDEFGHcan anyone please help me sorting out this problem.I tried this :<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*) index.php?id=$1 [L]
</IfModule>Please help me. | Unable to write a rewrite rule in .htaccess for my php website |
Have your rules like this:RewriteCond %{HTTP_HOST} ^mainsite\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_Host} ^(.+?)\.net$ [NC]
RewriteRule ^(.*)$ http://%1.com/$1 [L,R=301] | I have looked for the solution everywhere but couldn't find the exact solution I am looking for. I am not good at htaccess stuff. Need some help.I have enforced "www" in my htaccess file and its getting on the way when I tried to create a subdomain.I am using this setting i found and so far its working fine without subdomain.RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_Host} ^(www\.)?example\.net$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]After creating a subdomain, its addding "www" at front and getting redirected to main site instead of subdomain.For example: folder.domain.com -> becomes -> www.folder.domain.com (displayes the main site)What modification is needed on top of what I have in this htaccess?Enforce "www".Also allow subdomain if its not "www".plus subdomin URL from ".net" also redirects to ".com"By the way my main site is in codeigniter and I also have this:RewriteCond $1 !^(index\.php|js|media|style)
RewriteRule ^(.*)$ /index.php/$1 [L]Wanted to install blog on subfolder and use it as subdomain.easy way was to modify (add "blog")RewriteCond $1 !^(index\.php|js|media|style|blog)
RewriteRule ^(.*)$ /index.php/$1 [L]then I an access it as www.domain.com/blogBut I wanted it neat and clean way so that controller created URL will not conflict with sub-folders. Probably not allow access subfolders directly.Thanks | htaccess enforce "www" yet allow subdomain access |
You can installmod_geoipon your server, which enables database-based geolocation lookup directly inside Apache. Look at the examples for exactly the scenario you talk about.The advantage would be much better performance, since the lookup will be done locally using a database, instead of needing to call an external web service. It also requires virtually no code once this is set up, easing maintenance. You will only have to make sure your local copy of the lookup database is regularly updated, typically with a weekly/daily cron job.You can rewrite the URL in any way you want appending any parameters you want.SEO-wise it should have no effect at all compared to PHP based redirects, since to the client the behaviour appears exactly the same. | I am writing a small script in which it redirects to country specific landing pages(example: if you come from Germany you will be re-directed toxyz.com/de/) this redirection happens using index.php which connects to web service returns the country the user is accessing the website from then I redirect the user using 301 to a the new page xyz.com/de/I have two questions1- Can the same functionality integrated withmod_rewrite, if so what is the advantage in terms of performance and SEO quality?2- Can the mod_rewrite save the query string includingGCLIDon the redirects (as I am concatenating the$_SERVERto php redirection | IP Geo location with Mod_Rewrite & PHP |
You're close but your regex is little bit off track. Try this rule:RewriteEngine On
RewriteBase /mywebsite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]{4})/([0-9]{2})/(.+?)\.html$ $1/$2/$3/ [L,NC,NE,R=301] | I am having an issue on a WordPress-based website I run regarding a Rewrite Rule in my .htaccess file.Recently overhauled the website and my permalink structure has changed. Previously, it was/%year%/%monthnum%/%postname%.htmlNow, it is/%year%/%monthnum%/%postname%/The issue I'm running into is Google having all the .html links stored. So, visitors who follow the links via Google get a 404.What I would like to happen is that anytime an incoming URL has the .html on the end and matches the permalink structure format, redirect to the same URL, just without the html extension.I tried adding a Rewrite Rule to my .htaccess file and am having issues with it not working. I'm not sure what that issue is.RewriteEngine On
RewriteBase /mywebsite.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]{4}+)/([0-9]{2}+)/([a-zA-Z0-9-]+).html$ $1/$2/$3/ | Rewrite old URLs using htaccess and regex |
It's an apache bug, see belowhttps://issues.apache.org/bugzilla/show_bug.cgi?id=51223You can recompile Apache with the patch if you're feeling brave.... | I'm trying to download a static file from another domain. In my .htaccess file, which is in the root directory:Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Accept, If-Modified-Since, Origin"
Header set Access-Control-Allow-Methods "GET, OPTIONS"And here's the request-response cycle where a browser downloads the resource twice:GET /file HTTP/1.1
Host: www.example.com
Accept: application/json
Origin: http://www.mydomain.com
HTTP/1.1 200 OK
Date: Sat, 07 Sep 2013 21:01:35 GMT
Server: Apache
Last-Modified: Sat, 07 Sep 2013 20:14:45 GMT
Content-Length: 2
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Accept, If-Modified-Since, Origin
Access-Control-Allow-Methods: GET, OPTIONS
Content-Type: application/json
[]
GET /file HTTP/1.1
Host: www.example.com
Cache-Control: max-age=0
Accept: application/json
Origin: http://www.mydomain.com
If-Modified-Since: Sat, 07 Sep 2013 20:14:45 GMT
HTTP/1.1 304 Not Modified
Date: Sat, 07 Sep 2013 21:01:40 GMT
Server: ApacheThe second time you can see that since the file hasn't been modified, the server responds with a304 Not Modified. Why are the CORS headers not being set for the second response? | CORS Headers Not Being Set |
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^page_id=([0-9]*)&category=(.*)$
RewriteRule ^(.*)$ /%1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPressWorks. And redirects from:http://test.com/index.php?page_id=70&category=FootageTo:http://test.com/70/FootageUPDATED:RewriteRule ^(.*)/(.*)$ /index.php?page_id=$1&category=$2 [L]This rule Works and makesinner redirect(without url change) from:http://test.com/70/FootageTo:http://test.com/index.php?page_id=70&category=Footage | Can we rewrite WordPress page/ghijto show the contents of page/faq, when permalinks are already enabled?My page isexample.com?page_id=70&category=Footage. After enabling permalink it is showingexample.com/video-category?category=Footage. I want it to look likeexample.com/category/Footage.Any help in this will be appreciated.Current.htaccess:<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule> | WordPress .htaccess not working for rewriterule |
. Can this url changed into this format with .htaccess without moving kurum.php file into a new directory?http://fxrehber.com/kurumlar/7-ata-foreks(I can add "/kurumlar" directory by .htaccess but my css and image link won't work)I used full path of the image inside php file and it works with this:
.htaccess:<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^kurumlar\/([0-9]+)-([a-zA-Z0-9-_]+)$ /kurum.php?id=$1&sef=$2
</IfModule>kurum.php:<?php
var_dump($_REQUEST);
?>
<img src="/sites/default/files/1.png">2 . Can I pass the id value without mentioning it in the SEF url like this:http://fxrehber.com/kurumlar/ata-foreks(which is the best option for me)Only ifata-forekscan be used as a unique alias of an article and used instead of id."Is there a disadvantage about this?"Yes. Searching by string is slower, then by integer. | I'm a newbie about .htaccess and rewrite functions.
I've searched many pages but I couldn't find a solution.
Here's my problem:I have urls in these formats in my kurum.php file:fxrehber.com/kurum.php?id=$krmID&sef=$sefso my normal url is:http://fxrehber.com/kurum.php?id=7&sef=ata-foreksrelated part of my .htaccess is:<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^([0-9]+)-([a-zA-Z0-9-_]+)$ /kurum.php?id=$1&sef=$2
</IfModule>So I can get SEF urls in this format:http://fxrehber.com/7-ata-foreksI have two questions:1 . Can this url changed into this format with .htaccess without moving kurum.php file into a new directory?http://fxrehber.com/kurumlar/7-ata-foreks(I can add "/kurumlar" directory by .htaccess but my css and image link won't work)2 . Can I pass the id value without mentioning it in the SEF url like this:http://fxrehber.com/kurumlar/ata-foreks(which is the best option for me)If I cannot do this, do I have to use only $sef variable to select articles from the database? Is there a disadvantage about this?I hope this is enough explanation about my problem.
Thank you. | adding directory name into SEF url and also passing id value without using it in url |
I was able solve this without altering .htaccess and instead just placing my sub directory within '/content'. | I'm trying to run a non-Zend php application within a sub directory of a Zend site. I'd like to bypass the Zend application for all files within the sub directory '/branches' in .htaccess. So far none of the solutions I've found have worked. Here is the current .htaccess file:RewriteEngine on
RewriteBase /
# WWW Resolve
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^web/content/(.*)$ http://www.domain.com/$1 [R=301,L]
# Eliminate Trailing Slash
RewriteRule web/content/(.+)/$ http://www.domain.com/$1 [R=301,L]
# Route Requests
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]Can this even accomplished in .htaccess? | Using .htaccess to bypass Zend Framework and run different framework in sub directory |
+50Are you strictly limited to Netbeans v7.2? If not, you can make use of the latest builds. It was announced earlier.https://blogs.oracle.com/netbeansphp/entry/toggling_comments | Is there any way to get theToggle Commentcommand working for .htaccess files in Netbeans 7.2? I already got used to the according keyboard shortcuts in php, css, js and css files. As syntax highlighting is supported in 7.2, maybe it's possible to achieve that by changing the config?EDIT: I am not limited to Netbeans 7.2 | "Toggle Comment" for .htaccess files in Netbeans 7.x? |
Try adding these rules (keep the ones you already have):RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/([^/]+)/.+$
RewriteCond %{DOCUMENT_ROOT}/%1.php -f
RewriteRule ^([^/]+)/(.+)$ /$1.php?page=$2 [L]This is more or less like what you've got with the exception of using a%1backreference to check if thefirst part of the URIexists as a php file. This is the match for the first part:RewriteCond %{REQUEST_URI} ^/([^/]+)/.+$And this is the fheck to see if the([^/]+)grouping exists as a php file:RewriteCond %{DOCUMENT_ROOT}/%1.php -fEverything else is to match what's after the first/and make that thepagequery string param. | I have a site, which successfully passes the content after the first slash to a specified .php file. (elegantly: remove ".php")site.com/azamat to site.com/azamat.phpRewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC]How can I add additional parameters to these rules, so I can pass "page" parameters, like:site.com/azamat/bagatov to site.com/azamat.php?page=bagatovorsite.com/thisisthefile/andparams to site.com/thisisthefile.php?page=andparams | How to pass parameters in Rewrite Rules with specifying the .php file name? |
First check if the requested URLs is not a file or folder. This will prevent the redirect loop for URLs like/user.phpRewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-.]+)$ user.php?user=$1 [L,QSA] | I currently have a .htaccess file set up with this rule:RewriteRule ^([a-zA-Z0-9_-]+)$ user\.php?user=$1 [L]which works as expected:mysite.com/joebecomesmysite.com/user.php?user=joeHow could I change the regex to include periods in a possible username?For example I would likemysite.com/joe.bloggsto go tomysite.com/user=joe.bloggsCurrently this brings up a 404 missing page error.I have tried^([a-zA-Z0-9\._-]+)$ user\.php?user=$1 [L]But this produces an internal error 500 (I think this is due to an infinite loop: user.php is designed to redirect to the homepage if no user is specified.)I'm pretty new to all of this (regex especially). Thanks for any help! | escape period (.) character in mod_rewrite regex |
You can use negative lookahead like this:Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# redirect to /Project1/ if it is not already /Project1/
RewriteRule ^((?!Project1/).*)$ Project1//$1 [L,NC] | how could i get Apache to redirecthttp://localhost/index.php
http://localhost/create/index.php
http://localhost/create/contact.php
http://localhost/engage/page1/services.phptohttp://localhost/Project1/index.php
http://localhost/Project1/create/index.php
http://localhost/Project1/create/contact.php
http://localhost/Project1/engage/page1/services.phprespectively?Essentially I need to append "Project1" (or whatever other string I see fit) to the BEGINNING of the url pathThanks | append path directory to url using htaccess |
My opinion is that PHP handling is much better. The only possible minus is that it could be slower, but not so much, in overall page generation time you won't notice any difference. But the disadvantages are:if your site grows, you have to provide new rules in .htaccess
every time, which is not convenient. If you,for example, want to add
one more GET argument to some script call, you have to modify the
rules again.it is not comfortable, when you move from one host
to another. in some cases you will need to change the directory
structure, and all rules, which depend on it.if you, for some reason, decide to move your site from Apache to nginx, IIS, or some
other server, you will have lots of trouble converting your
.htaccess rules to some other server format.So it's definitely better to handle these by PHP. | When using URL rewriting for beautification, are there any thoughts on whether to do your content calculations in a PHP script or to hard code it into the .htaccess file?For instance, WP adds the simple rule to the .htaccess fileRewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]Which directs everything to the index.php page. Then it has a PHP script (canonical.php) parse the $_SERVER['REQUEST_URI'] to then figure out what content to actually pull up.Instead of using PHP to handle all of this, it could be entered directly into the .htaccess file passing the query items from the URL, similar to:RewriteRule ^products/([0-9][0-9])/$ /productinfo.php?prodID=$1Does anyone know the advantages/disadvantages of the two methods? I'm thinking that the PHP method offers a bit more flexibility, but I may be wrong. I have no idea of which has more overhead though. | For URL rewriting, use .htaccess or PHP to determine content used? |
+50Even if you could bypass browser limits, doing so would be bad net citizenship. Basically, that would be setting out to use more of the user's resources than the user has authorized. Don't do it.I don't think YouTube is locally caching more than your browser is allowing. I view a large HD video file and reload the page and the video is not preloaded. I don't see what you say you're seeing in the comment on your question.Of coures, that behavior may be browser-dependent.This postshows cache sizes for different browsers as of last year and they are certainly as large or larger now. | I'm using flowplayer, and told .htaccess to cache flv files for 30 minutes. When the files are under 5mb it caches, if over that, it doesn't. How do I force cache like youtube does?5mb from what I've found out is a browser default. If youtube is able to bypass that, I should be able to as well. Any ideas? | Caching larger flv files 5mb + |
mod_gzipis an obsolete part of Apache 1.x, having been replaced bymod_deflatein Apache 2.Thismod_deflateconfiguration makes YSlow happy here:<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/css text/html text/plain text/xml
DeflateCompressionLevel 9
</IfModule>The only reason there are twoAddOutputFilterByTypelines is to avoid horizontal scrolling. | I'm getting used toFirebugandYSlowin particular. One of the things I'm looking at is the gzip compression. YSlow still gives my site an "F" and indicates that my CSS and JavaScript files are not being compressed.However, if I run an external gzip test against my site (such ashttp://www.gidnetwork.com/tools/gzip-test.php) it tells me that gzip is working and gives me my savings, although I think this may just be the HTML.This is the relevant section of my.htaccessfile:<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.css$
mod_gzip_item_include file \.(html?|txt|js|php|pl|jpg|png|gif)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>Why does YSlow not agree with the external gzip test? | gzip working but YSlow indicates it's not |
This is what a person in the forums told meyou definitely have something in place. Every single path I type in
after the url leads me to the home
page.Try changing your URL Protocol from
AUTO to something else. (this can be
found in the config/config.php file)i changed it to “REQUEST_URI” and it works ! | when i try to make AJAX request with jQuery as a response i get the html of the same page !
here is a live preview (edit not available due to me fixing it )here are my files
Edit : I have made changes to some of the filesmain controller :Class Main extends Controller {
function Main()
{
parent::Controller();
}
function index(){
$this->load->view('oxila_index');
}}Oxila_index view ( just the JS rest of the html is in the link above )<script type="text/javascript">
$(document).ready(function(){
$("#inv").hide();
});
$(document).ready(function(){
$("#submit").click(function(evt){
$.post("/ajax/process", {
url: $("#url").val()
}, function(response){
$("#output").html("");
$("#inv").show("slow");
$("#output").html(response);
}, "text");
evt.preventDefault();
});
});
</script>Ajax ControllerClass Ajax extends Controller {
function process(){
$data['url'] = $this->input->post('url');
$this->load->view('test',$data);
echo "hello world";
}
} | CodeIgniter AJAX bug returning same page |
I have done research and spoke to my hosting company as well.
If you are on shared hosting, all domains on the same server share the same settings formod_security,so it is not possible to access and/or editmod_securitythrough htaccess. If that was possible, you would modifymod_securityto affect all website on the server. On shared hosting it is only possible to inspect$_GETvariables through htaccess. | Can you filter/inspect POST method/requests with htaccess
For example, if you want to filter a$_GETvariable with htaccess to redirect if a pattern is matched, it would look like this:RewriteCond %{QUERY_STRING} <script> [NC]
RewriteRule .*$ /mylogPage.php? [L,R=301]Can you do a similar filter for $_POST variables?I have tried many variations including an attempt to modifymod_securitythrough htaccess. I assume in htaccess it will have something to do with:RewriteCond %{REQUEST_METHOD} POST.I have triedRewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} <script> [NC]
RewriteRule .*$ /mylogPage.php? [L,R=301]But it only redirected the pageIf this should be done through mod_security, can one edit mod security through htaccess? What would the syntax look like? I have tried but was not successful. | Can you filter/inspect POST method/requests with htaccess? |
Azure CDN has a rules engine with which you can redirect a request:https://learn.microsoft.com/nl-nl/azure/cdn/cdn-standard-rules-engine | I have a static website hosted on Azure using a storage account with the option 'Static website' enabled. I want users to be able to access the website using the 'https' protocol. So I created a CDN with 'Custom HTTPS' enabled in order to access the content with the https protocol. This works great when accessing the website on the EndPoint Hostname and Origin Hostname. However if I access the website with the http protocol I get the error 'AccountRequiresHttps'. I tried to fix that by using a '.htaccess' file in the root folder to redirect 'http' requests to 'htpps' requests, which does not seem to work.Content of '.htaccess' file:RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]Is the '.htaccess' file correct? Or is there a way to enable the http protocol while keeping the https protocol? Or is there another way to redirect http to https? | Static website on Azure using htaccess file for forcing https |
The problem was that the .htaccess didn't have a 301 redirect. Once I added that, everything redirected smooth:RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L] | I am forwarding my http traffic to https with a .htaccess file like this:RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}This works everywhere except on iOS safari. When I go to the http address on iOS safari, the browser hangs because there is no where to go with http.What can I do to forward http to https on iOS Safari? | forwarding http to https doesn't work on iOS Safari |
Try This one, in your Apache configure file/etc/apache2/sites-available<VirtualHost *:8080>
ServerName serv1.example.com
ServerAlias serv1.example.com
DocumentRoot "C:/www/dev/public"
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory "C:/www/dev/public">
Options All
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
# Log file locations
LogLevel warn
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" commonAnd in yourc:\www\dev\public\.htaccess<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]I hope this would work. for more information follow these links.Multiple laravelsites on single apache server,multiple web sites in single laravel installation | I have Apache 2.4 running on Windows Server 2012 with PHP 5.6.23 on port 8080.Assume that the domain to my server is "serv1.example.com" I need to run 3 Laravel instancesproduction,staginganddevusing the following linksserv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/devI found anotherSO questionwhich seems to be doing the same thing. But when I tried to do the same thing I get the following errorForbidden
You don't have permission to access /dev on this server.Here is what I have done so far. In myhttpd-vhosts.conffile I added the following VirtualHost<VirtualHost *:8080>
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
DocumentRoot "C:\www\dev\public"
ServerName serv1.example.com
ServerAlias /dev
<Directory "C:\www\dev">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>Then I changedc:\www\dev\public\.htaccessthe code to the following<IfModule mod_rewrite.c>
#Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php/?$1 [L]
</IfModule>What did I do wrong here? how can I access each instance using the same domain? | How to run multiple instances of Laravel on the same domain? |
The Http to Https redirection for Another domain failed because Your Rule is missing the following line :RewriteCond %{HTTPS} offTry :# redirect another domain to www.maindomain.com
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC]
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L] | I have a no clue why this fails. I just want to redirect all domain towww.maindomain.comand alsohttptohttps, what am i missing?# redirect http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# redirect without www to www
RewriteCond %{http_host} ^maindomain.com [nc]
RewriteRule ^(.*)$ https://www.maindomain.com [r=301,nc]
# redirect another domain to www.maindomain.com
RewriteCond %{HTTPS} off # this i was missing
RewriteCond %{HTTP_HOST} ^(www\.)?anotherdomain.com [NC]
RewriteRule ^(.*)$ https://www.maindomain.com [R=301,L]http://maindomain.comtohttps:/www.maindomain.com/workshttp://anotherdomain.comtohttps:/www.maindomain.com/workshttps://anotherdomain.comtohttps:/www.maindomain.com/fails | Apache2 redirect to another domain with ssl |
Have it like this:# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^language/nl/article-1/?$ /language/nl/fa1-artcile-1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress | For my current project I have to Redirect 301 some links but when you enter them with some extra get parameters that parameters need to be suffixed on the new url.Example:Old:
/language/nl/article-1/?test=123new:
/language/nl/fa1-artcile-1/?test=123So I use the following code: (which works fine on my dev env)RewriteEngine On
Options +FollowSymLinks
RewriteBase /language/nl
RewriteRule /artcile-1/* /language/nl/fa1-artcile-1/$1 [R=301,L]But once on my production env it does not work, it still redirects to new url but, the get parameters are not appended on the new url.Edit: It does redirect but it does not append the parameters.Edit 2: full fill# 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 WordPressThe rewrite rule(s) come before the wordpress part and I have about 30 of them.Any suggestions? | RewriteRule not working on production server |
This is an interesting issue when you use CloudFlare's Flexible SSL option alongside WordPress. WordPress, in it's core, has anis_sslfunction that doesn't account for reverse proxies. Therefore when you redirect to SSL you can geta redirect loop if using Flexible SSL.The easiest way to fix this is toinstall Mod_cloudflareon Apache.Instead, you can add the if statement to your wp-config.php file to resolve this issue:if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$_SERVER['HTTPS'] = 'on';
}If you use this method instead of installing Mod_cloudflare ensure that you use the "X-Forwarded-Proto" header instead of SSL for any redirects. | I created my WordPress application on OpenShift, and it responds to the URL blog-porta8080.rhcloud.com.I created 2 aliases on OpenShiftI bought my domain (porta8080.com.br) from a brazilian registrar that don't allow me to add CNAME records without a subdomain like www.So I created an account on CloudFlare, registred my domain and moved my domain to the CloudFlare DNS servers.Then I added 2 CNAME records to CloudFlareI even installed the CloudFlare plugin they say would help mehttps://wordpress.org/plugins/cloudflare/But when I go tohttp://porta8080.com.brit fails to load the page due to a redirect loop error. I tested on chrome and on Firefox and both throws the same error. Chrome says "ERR_TOO_MANY_REDIRECTS" and inspecting the requests, it gives me several "301 error: Moved Permanently"The wp-admin page doesn't give me an error. The only thing I can think about is its own .htaccess file.This is my .htaccess (the one in Openshift is probably without theblog/parts, I just changed the permalink in both and that's the resulting .htaccess on my machine)# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPressGot any ideas?@EditThere is a problem on my .htaccess for sure. I commented it and put a message on index file and it gets there both by www and without it.Would you guess why? | Redirect loop with CloudFlare and OpenShift and a WordPress application |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.