mod-rewrite

Redirect www. to non-www and redirect all http to https with .htaccess

橙三吉。 提交于 2021-02-05 07:44:28
问题 Million times asked question, but after reading many of the answers here on SO I still can't figure this out. I need to redirect all requests like below: http://domain.tld > https://domain.tld http://www.domain.tld > https://domain.tld https://www.domain.tld > https://domain.tld http://sub.domain.tld > https://sub.domain.tld (when .htaccess placed in subdomain folder) Until now, I was using the code from html5boilerplate, that solved www to non-www <IfModule mod_rewrite.c> RewriteCond %{HTTPS

Pretty URL for .html with parameters

北战南征 提交于 2021-02-05 07:10:29
问题 I have a website which consists only from .html frontend and I want to have pretty URLs. My goal is to create something like this http://test.com/mypage.html => http://test.com/mypage http://test.com/mypage1.html => http://test.com/mypage1 and for one specific page http://test.com/my-prettlink.html?id=1 => http://test.com/my-prettlink/1 I tried this .htaccess which is located in project root but only removing .html works. Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine

Remove exact string from end of url apache htaccess rewriterule

心已入冬 提交于 2021-01-29 04:08:34
问题 I have all my URLs like this example: http://domain.com/="%7b%7bstore I would like to create a RewriteRule to remove the trailing ="%7b%7bstore from the url. The string is always at the end. The rule has to leave any other query string, url part untouched. I figured that %7b translates to { . I got this far with the rule, but can't figure out the rest: RewriteRule ^/?(.*)store$ /$1 [L,R=301] Could anybody help? Thank you! 回答1: You can use this rule as your first rule in root .htaccess:

mod_rewrite based on cookie value

て烟熏妆下的殇ゞ 提交于 2021-01-29 03:51:26
问题 I have a multilingual website and I need change the URL based on a cookie value. For example, I have $_COOKIE["lang"] = "en" and I want to change the URL to either www.mydomain.com/en/rest/of/the/url or en.mydomain.com/rest/of/the/url . How can I do this? 回答1: Use any kind of redirect available to you. In vanilla php you can user header(). mod_rewrite is a webserver-based directive, it works well before your php script gets a chance to kick in, and it most definitely cannot touch cookies.

mod_rewrite based on cookie value

僤鯓⒐⒋嵵緔 提交于 2021-01-29 03:35:46
问题 I have a multilingual website and I need change the URL based on a cookie value. For example, I have $_COOKIE["lang"] = "en" and I want to change the URL to either www.mydomain.com/en/rest/of/the/url or en.mydomain.com/rest/of/the/url . How can I do this? 回答1: Use any kind of redirect available to you. In vanilla php you can user header(). mod_rewrite is a webserver-based directive, it works well before your php script gets a chance to kick in, and it most definitely cannot touch cookies.

htaccess redirect from www to non-www

巧了我就是萌 提交于 2021-01-29 03:09:29
问题 I am new to this. Code from my .htaccess file goes like this: RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^(.*) http://%1/$1 [R=301,NE,L] Redirect 301 /abc/ /abcnew/ I want this to redirect from www to non-www i.e., from http://www.example.com to http://example.com I copied: RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^(.*) http://%1/$1 [R

How to prevent direct access to files but allow files in webpages

血红的双手。 提交于 2021-01-28 23:11:34
问题 I'm trying to use mod.rewrite to deny direct access to files on my web server, e.g. http://domain.tld/reports/imareport.pdf or http://domain.tld/img/img1.png, and I've used the answer on this question: (htaccess) How to prevent a file from DIRECT URL ACCESS? That page suggests using mod.rewrite like this: RewriteEngine on RewriteRule \.(png|pdf|htm)$ - [F] Using mod.rewrite in this manner works fine for denying access to PDFs, but other files that are ordinarily included in a page such as

.htaccess redirect with URL friendly (mod_rewrite)

独自空忆成欢 提交于 2021-01-28 21:26:11
问题 I'm using RewriteRule in my URLs RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&page=$2 [L,QSA,NC] Now I need to create a 301 redirect. So I do that: Redirect 301 /port/reestruturacao-financeira http://website.com/port/reestruturacao-corporativa/ The result is wrong: http://website.com/port/reestruturacao-corporativa//?lang=port&page=reestruturacao-financeira How can I fix that? redirect http://website.com/port

Rewrite URL Codeigniter

无人久伴 提交于 2021-01-28 18:00:36
问题 i'm using Codeigniter for my web app, i changed the structure of the project as the following : my_Project --- application --- public_html --- resources --- system I created the folder public_html to seperate my public files from the classes .. etc, but now i have to call this url every time : my_project/public_html/controller/action i want it to be this way : my_project/controller/action I already moved out the index.php from the URL using the rewrite mode, but i can't seem to remove the

.htaccess remove duplicate part of a URL

折月煮酒 提交于 2021-01-28 17:35:55
问题 some bug in my online catalog SEF URL generation created a situation where some category slug is added to the URL twice. to fix this i would like to use .htaccess to remove the this part of the URL and have the whole URL shift up one level including URL's which also include a product under them. the duplicate occurrence is of the sub-category painting-tools under the category tools so the wrong URL looks like this: /store/items/catalog/tools/painting-tools/painting-tools or /store/items