mod-rewrite

.htaccess to change the url path

耗尽温柔 提交于 2019-12-12 09:16:42
问题 I have tried several examples of solutions that I have found here on StackOverflow but none of them seem to work correctly. I have a Magento store that I need to redirect an old store code url to the new one. For example: The old url looked like this. www.example.com/something_en In the above example I need to be able to modify any url that contains to the path something_en and change it to something like in the next example. www.example.com/something Any help is much appreciated. 回答1: Make

Sub-Domain Masking via htaccess

ε祈祈猫儿з 提交于 2019-12-12 09:07:58
问题 EDITED I set-up a wildcard subdomain dns zone on my server and would like to have each subdomain load the contents of the /users/ direcotry using .htaccess and mod-rewrite. I would like the URL to remain unaltered in the browser bar so that it shows: http://username.domian.com/../../ while showing the contents of: http://www.domain.com/users/username/../../ Additionally, I would like to redirect (change the URL) to the subdomain version if the www version of the URL is accessed. I'm not

phpinfo() mod_rewrite

元气小坏坏 提交于 2019-12-12 08:31:49
问题 I'm attempting to perform some url rewriting, and after looking at the phpinfo file, I can't see any mention of this.. My host is FastHosts. Should I be looking for something else in the phpinfo() or should I assume that mod_rewrite is simply disabled ? 回答1: mod_rewrite is an apache module, not a PHP module. It isn't visible in phpinfo() . Create an .htaccess in some subfolder and make sure it contains: RewriteEngine on Point your browser to the folder. If you get a Server Error, it isn't

Regex match this OR that?

廉价感情. 提交于 2019-12-12 08:29:09
问题 What is the regex for this? Match if string NOT ( ends in .php OR ends in .html OR contains / ) Thank you! Edit: I need the NOT part because the expression is to be used on an Apache mod rewrite, since I can't change the logic of mod _rewrite to avoid the NOT. Edit: My initial effort was ([^/]+)(.html)$(^.php)$ -- which is monstrusly wrong 回答1: Apache mod_rewrite does support negation, according to this document. In mod_rewrite, the NOT character ('!') is also available as a possible pattern

How to 301 redirect with or without the trailing slash?

廉价感情. 提交于 2019-12-12 08:28:09
问题 I want to redirect site.com/login OR site.com/login/ to site.com/wp-login.php Here's what I have so far: RewriteRule ^login$ "\/wp\-login\.php" [R=301,L] But it doesn't redirect /login/ (with the trailing slash). How to tell htaccess to redirect with or without the trailing slash? Thank you, Cris 回答1: You want the expression to see the / as optional ^login/?$ The ? token will allow for the zero or one occurence of the / 来源: https://stackoverflow.com/questions/7983726/how-to-301-redirect-with

PHP: How can I get the URL that has been rewritten with mod_rewrite?

自闭症网瘾萝莉.ら 提交于 2019-12-12 08:23:34
问题 For example, if I rewrite /category/topic/post/ to /index.php?cat=1&topic=2&post=3 , how can I get /index.php?cat=1&topic=2&post=3 using PHP? 回答1: You can recreate it pretty easily. $_SERVER['PHP_SELF'] will still give you the correct file name for the script. This should do the trick: $url = $_SERVER['PHP_SELF']; $parts = array(); foreach( $_GET as $k=>$v ) { $parts[] = "$k=" . urlencode($v); } $url .= "?" . implode("&", $parts); $url will now be the URL you're looking for. EDIT: @carpereret

How to reference the current directory from .htaccess using mod_rewrite?

旧巷老猫 提交于 2019-12-12 08:23:03
问题 I'd like to use mod_rewrite to make pretty URLs, but have a single version of the .htaccess file that can be used for any user on a server. So far I have the standard pretty URL .htaccess: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] Ideally, I would like something similar to RewriteRule ^(.*)$ %{URL of this file's directory}/index.php/$1 [L] This documentation would lead me to believe that what I want is not

Rewrite css/js paths

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 08:14:24
问题 So I rewrote my paths to something like: URL/really/nice/paths/ using mod_rewrite rules like this: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [PT,L] </IfModule> The question is how could I rewrite the paths for js/css/image files too, so when they are requested with a relative path from URL/really/nice/path/ to be served from URL/scripts/ , URL/styles/ and URL/images/ folders instead?

Use PHP to Dynamically Add To .htaccess File?

痴心易碎 提交于 2019-12-12 08:11:57
问题 What I am trying to do is automate the process of going live with websites. These websites are all dynamically created using htaccess, so here is an example: RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC] RewriteRule ^(.*)$ /folder%{REQUEST_URI}?%{QUERY_STRING} [QSA,L] What I do is add a domain alias for domain.com , and then point it to my server IP and the htaccess file makes it view what is in the /folder. It works fine but we are planning to have

.htaccess redirect from GET variable to url string

霸气de小男生 提交于 2019-12-12 08:01:23
问题 I need to redirect /search?keywords=somesearchterm to /search/somesearchterm This seems incredibly basic but I've been pounding my head against it for an hour. Thanks for taking the time to look at this. 回答1: You want to implement what is called a "301 Redirect" with mod_rewrite. RewriteEngine ON RewriteRule ^/search\?keywords=somesearchterm$ /search/somesearchterm adding regular expressions: RewriteEngine ON RewriteRule ^/search\?keywords=(.+) /search/$1 [R=301,L] R=301 means provide a 301