mod-rewrite

Rewrite rule to add .html suffix

北慕城南 提交于 2019-12-24 11:21:42
问题 I am using WordPress. I need to add a custom rewriterule. I want to have two URLs for a single page. For example: www.test.com/abc <--- At present this is implemented & working fine. www.test.com/abc.html <--- Need to add .html at back side. I want to allow access to the same page with .html extension. How can I do that? 回答1: I explain through comments. RewriteEngine on RewriteBase / # Make sure it's not an actual file or directory RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST

Domain name in mod_rewrite RewriteRule

对着背影说爱祢 提交于 2019-12-24 11:19:02
问题 The task is to get referer domain and send it to my script by RewriteRule. My decision is SetEnvIf Referer "^https?://(.*)/" myref=$1 RewriteRule ^(.*)$ script.php?referer=%{ENV:myref} It works right but I wonder if there are any ways to do it (perhaps with RewriteCond)? 回答1: mod_rewrite has a variable named %{HTTP_REFERER} . It contains what you expect. You can use it like this: RewriteCond %{REQUEST_URI} !^/script\.php$ RewriteRule ^ script.php?referer=%{HTTP_REFERER} [L] See the

htaccess rewrite rule for a part of URL

淺唱寂寞╮ 提交于 2019-12-24 11:17:44
问题 I try to change over htaccess from http://www.mydomain.com/pictures/generated/product/1/280_280_75/nopic.jpg to http://www.mydomain.com/pictures/generated/product/1/280_280_75/nopic1.jpg Here is my rules RewriteCond %{HTTP_HOST} ^mydomain\.com RewriteRule nopic\.jpg$ nopic1\.jpg It works in some way;) The whole URL will be changed just to "nopic1.jpg". The question is: How can I change only the last part of URL? 回答1: This should work: RewriteRule ^(.*)nopic\.jpg$ $1nopic1\.jpg 来源: https:/

mod_rewrite www to no-www and http to https simultaneously

旧时模样 提交于 2019-12-24 11:10:57
问题 I currently have mod_rewrite in place with code I found to redirect all requests to the same URL without www. What I'm trying to do now is configuring Apache mod_rewrite to do the following, without any wasted actions/additional redirects. http:// to https:// http://www. to https:// I'm not familiar with it, but in pseudo code, http(s)://(www.)domain.com to https://domain.com for solely the URLs at the top level, excluding sub domains. 回答1: You just need one rule for both conditions: put this

Rewrite folder to subdomain with htaccess

烈酒焚心 提交于 2019-12-24 11:01:04
问题 I want to rewrite all addresses after this http://example.com/users/* to this http://*.example.com/ for example: http://example.com/users/admin http://admin.example.com/ I want to do this in a .htaccess file. I now have this, but it dont work: RewriteEngine On RewriteCond %{HTTP_HOST} ^.example\.com$ RewriteRule ^users/([^/]+)/?$ http://$1.example.com/ [NC,R=301,L] Can anyone help me? Thanks 回答1: Remove the dot before the domain in the RewriteCond : RewriteEngine On RewriteCond %{HTTP_HOST}

only top condition is working not others for url rewriting?

余生颓废 提交于 2019-12-24 11:00:53
问题 This is my htaccess code for url-rewriting. I have a problem here. Options +FollowSymLinks -MultiViews -Indexes <IfModule mod_rewrite.c> DirectoryIndex index.php RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php ErrorDocument 404 404error.php RewriteEngine On RewriteRule ^([A-Za-z0-9-]+)?$ specification.php?url=$1 RewriteRule ^([A-Za-z0-9-]+)?$ news.php?url=$1 RewriteRule ^([A-Za-z0-9-]+)?$ social.php?url=$1 </IfModule> here

RewriteRule works but ugly URL shows instead of pretty one

北战南征 提交于 2019-12-24 10:59:07
问题 This is my .htaccess file: RewriteEngine on RewriteBase /admin RewriteRule menu/([0-9]+)/([0-9]+)/([a-z0-9]+) http://www.mysite.com/admin/index.php?m=$1&o=$2&token=$3 [R,L] I had to include the full URL because without it, it kept redirecting to http://www.mysite.com/menu/1/1/login.php instead of mysite.com/admin/login.php So I rewrote my links, so that they look like this: <a href="/admin/menu/1/1/bl4h1234">Some link</a> And that works fine, but the URL shows in the address bar as the ugly

.htaccess rewrite rule with static files gives me 404, what I'm missing?

余生颓废 提交于 2019-12-24 10:56:10
问题 My project (Silex) has a front controller web/index.php and assets in web/css/* , web/img/* and so on. I've placed the following .htaccess file in the root of the public html folder: <IfModule mod_rewrite.c> Options -MultiViews RewriteEngine On RewriteBase web RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] </IfModule> Every request should be rewrited to web folder ( RewriteBase web directive) and if file doesn't exist ( !-f ) it should be routed to the front controller.

.htaccess add an extra word to add all my URLs

柔情痞子 提交于 2019-12-24 10:50:01
问题 I need to a add a extra word right after my domain name to all my website URLs. Lets say my url is http://www.example.com/somecategory/someproduct.html, it should be http://www.example.com/logado/somecategory/someproduct.html. Is it possible to do it with .htaccess file ? If so what should i add to my .htaccess file ? 回答1: You can use this code in your DOCUMENT_ROOT/.htaccess file: RewriteEngine On RewriteBase / # prefix each URL by /logado/ if it is not present RewriteCond %{THE_REQUEST} !\s

.htaccess causes issues in sub-folders

梦想与她 提交于 2019-12-24 10:49:11
问题 Here is my .htaccess to rewrite public/index.php I'm using the Laravel php framework. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} /(code|tmp) [NC] RewriteRule ^ - [L] RewriteRule ^((?!public/).*)$ public/$1 [L,NC] </IfModule> Here the folders 'code' and 'tmp' can be accessed like normal. If I add a set of nested folders, and add the default Laravel htaccess to remove the public/index.php <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options