mod-rewrite

htaccess rewrite index.php on root and subfolders

家住魔仙堡 提交于 2020-01-13 06:49:07
问题 I'm trying to redirect all requests to ./index.php?site=$1 while I only want to use the part behind the last slash. So I want www.mydomain.com/firstpage to become www.mydomain.com/index.php?site=firstpage and www.mydomain.com/subfolder/anotherpage to become www.mydomain.com/subfolder/index.php?site=anotherpage But right now www.mydomain.com/subfolder/anotherpage becomes www.mydomain.com/index.php?site=subfolder/anotherpage This is what I've got: RewriteEngine on Options +SymlinksIfOwnerMatch

How can I turn off QSA? (query string append)

♀尐吖头ヾ 提交于 2020-01-13 03:57:05
问题 I'm using Apache2 and mod_rewrite to hide my query strings. These are the rules in question. RewriteCond %{QUERY_STRING} ^query=(.*)$ RewriteRule (.*) /search/%1 [R=301,L] RewriteRule ^search\/?$ /search/?query=test [R=301,L] When I visit /search (or /search/ ) I am correctly redirected to /search/?query=test (as per the last rule) From there, the RewriteCond and RewriteRule should kick in and redirect me to /search/test , right? From what I understand the %1 in my first RewriteRule

mod_rewrite to remove .php extension AND preserve GET parameters

家住魔仙堡 提交于 2020-01-13 03:19:20
问题 I have looked at these solutions and none of them actually work properly on my end: mod_rewrite to remove .php but still serve the .php file? How to remove file extension from website address? How to use Apache Mod_rewrite to remove php extension, while preserving the GET parameters? and they just don't do the following, which is what I need done: 1) remove .php extension from files and instead of /index.php display /index 2) preserve GET parameters (which I read and store in session cookies

mod_rewrite: allow redirect but prevent direct access

…衆ロ難τιáo~ 提交于 2020-01-12 20:26:41
问题 I am currently using mod_rewrite to do an internal redirection RewriteCond %{REQUEST_URI} ^/pattern$ RewriteRUle .* file.php However I would like to prevent direct access to file.php by redirecting requests to that file to a page not found URL. RewriteCond %{REQUEST_URI} /file.php RewriteRule .* page-not-found.php The problem is that the second rule also applies when I do the first redirect and therefore breaks my first internal redirect. [Q] Is there a way to allow the first redirect but

non www .htaccess redirect - ignore other subdomains

只愿长相守 提交于 2020-01-12 03:38:11
问题 I have a .htaccess redirect for "non www" like this: RewriteEngine on RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] it is working. But, i have also some subdomains other than www. If I call for example http://shop.example.com it redirects me to: http://www.shop.example.com I dont want to write the subdomains into the .htaccess file, it should work automatically, just ignore anything else than www and '' like this: if subdomain =='' -> redirect to www

mod-rewrite redirect child URL to parrent URL

落花浮王杯 提交于 2020-01-11 13:41:06
问题 in .htaccess I would like to chop off anything after the 2nd '/'… so http://www.domain.com/parent/child/otherchild would be redirected to http://www.domain.com/parent/ 回答1: Add these rules to the htaccess file in your document root: RewriteEngine On RewriteRule ^([^/]+)/.+$ /$1/ [L,R=301] Not sure what you meant by pasting all that unreadable code in the comments, but you want to add exclusion conditions like I mentioned in my comments: AddType application/octet-stream vcf # BEGIN WordPress

htaccess pretty URL with PHP & URL variables

独自空忆成欢 提交于 2020-01-11 13:19:12
问题 hoping someone can offer some assistance here. This is an issue with multiple layers. In short, I want to have pretty URLs that use a URL variable to a file within a folder. So, I want http://www.example.com/?page=path/to/page to look like http://www.example.com/path/to/page/ On the index.php page, to load the above content: require_once('content/'.$_GET['page'].'.php'); Current htaccess configuration: RewriteEngine On # Add trailing Slash RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*[

.htaccess rewrite to default language folder?

╄→尐↘猪︶ㄣ 提交于 2020-01-11 13:11:12
问题 I have my site broken down into several folders by language: / /en/ index.php about-us.php faq.php ... /fr/ index.php about-us.php faq.php ... ... etc. I'd like to have a rewrite rule that automatically rewrites to the en folder if somebody tried to enter mydomain.com/about-us.php . FYI, I also already have a rewrite rule in place that removes the extension, so really I want to make sure that mydomain.com/about-us rewrites to mydomain.com/en/about-us . Here's my existing rewrite rule that

.htaccess Redirect non-www domains including subdirectoies to www and exclude subdomains

和自甴很熟 提交于 2020-01-11 13:11:04
问题 I know there's tons of docs on any one of these items, but I can't seem to find the .htaccess code to do all of them together. Goal/requirements: No prefix domain.tld redirects to www.domain.tld Subdomain'd domain (ex. mail.domain.tld) still goes to mail.domain.tld, i.e. does not get redirected to www.domain.tld Domain.tld/subdirectory redirects to www.domain.tld/subdirectory. NOTE: domains will vary, but subdirectory will always be the same, i.e. all domains have the subdirectory. For

.htaccess Redirect non-www domains including subdirectoies to www and exclude subdomains

微笑、不失礼 提交于 2020-01-11 13:08:53
问题 I know there's tons of docs on any one of these items, but I can't seem to find the .htaccess code to do all of them together. Goal/requirements: No prefix domain.tld redirects to www.domain.tld Subdomain'd domain (ex. mail.domain.tld) still goes to mail.domain.tld, i.e. does not get redirected to www.domain.tld Domain.tld/subdirectory redirects to www.domain.tld/subdirectory. NOTE: domains will vary, but subdirectory will always be the same, i.e. all domains have the subdirectory. For