mod-rewrite

.htaccess Remove WWW from URL + Directories

心不动则不痛 提交于 2019-12-17 08:23:07
问题 This seems to be a non-issue for many people (read: I can't find an answer), but I would like to update the following htaccess code to not only remove the 'www' from the URL, but also any sub-directories that are accessed. RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] With this, http://www.example.com/any/ resolves fine, but I want it to redirect to http://example.com/any/ as with the root. 回答1: I had the same problem (trouble stripping

How can I mod_rewrite and keep query strings?

北慕城南 提交于 2019-12-17 07:51:33
问题 I want to mod_rewrite a URL to another page, but then I also want any query strings added to be preserved. RewriteEngine On #enforce trailing slashes RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !# RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://localhost/siteroot/$1/ [L,R=301] RewriteRule ^apps/([A-Za-z0-9-_]+)/?$ index.php&app=$1 So if a user visits apps/app1/ , index.php?app=app1 is shown. However, I want to be able to preserve optional query strings, so that

Mod Rewrite redirect URL with query string to pretty url

為{幸葍}努か 提交于 2019-12-17 07:51:18
问题 I successfully changed my URLs from ugly ones with several parameters in the querystring to clean looking ones with the help of mod rewrite. However, there are many url's for my site. Rather than go back and edit the href attribute on each and every one of my anchor tags, I tried to write a redirect function in the .htaccess file that automatically redirects the old url to the new one. In my .htaccess file, I have the following: RewriteEngine On Redirect teams.php?league=$1&team=$2&year=$3

PHP Rewrite Rules

▼魔方 西西 提交于 2019-12-17 07:27:46
问题 The actually URL which my app uses is: http://site.com/search.php?search=iPhone but I would like it to be possible to achieve the same with http://site.com/iPhone I have no experience of rewrite rules, how can I set this up? The solution has worked but the new URL is displayed in the address bar. I thought it would have been possible to set this up so that it appears as though the page location is http://site.com/iPhone without changing to display http://site.com/search.php?search=iPhone Is

Set RewriteBase to the current folder path dynamically

核能气质少年 提交于 2019-12-17 06:27:11
问题 Is there any way to set RewriteBase to the path current folder (the folder which the .htaccess file is in) relative to the host root? I have a CMS and if I move it to the directory in my host it does not work unless I set the RewriteBase to the path of directory relative to the root of host. I would like my CMS to work with only copy and paste, without changing any code in htaccess. Update: For example: webroot - sub_directory - cms - .htaccess in this case I should write in the htaccess:

How to debug htaccess rewrite script

浪尽此生 提交于 2019-12-17 06:11:47
问题 I was wondering how to create and debug this kind of script that can become a bit of headache if you are not used to write them (like me). Do you use tool to create them? Any tips to debug what's going on instead of just create a local structure and see what's happening in the browser? 回答1: Note to readers: the old answer doesn't work anymore . As of version 2.4, Apache no longer allows the RewriteLogLevel and RewriteLog directives. Now they're all bundled with the single LogLevel directive

Case Insensitive URLs with mod_rewrite

大憨熊 提交于 2019-12-17 04:34:09
问题 I'd like for any url that doesn't hit an existing file, to do a lookup on the other possible cases and see if those files exist, and if so, 302 to them. If that's not possible, then I'm ok with these compromises: Only check the lowercase version Only check the first path portion For example http://example.com/CoOl/PaTH/CaMELcaSE should redirect to http://example.com/cool/path/camelCase (assuming the latter exists). but of course a full solution is much more useful to me and others 回答1:

Remove .php from urls with htaccess

て烟熏妆下的殇ゞ 提交于 2019-12-17 04:27:59
问题 EDIT: current .htaccess file: Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / ## hide .php extension snippet # To externally redirect /dir/foo.php to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] RewriteRule ^ %1 [R,L] # To internally forward /dir/foo to /dir/foo.php RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1.php -f RewriteRule ^(.*?)/?$ $1.php [L] My site is hosted in a subfolder of a domain connected to a

Remove 'index.php' from URL with .htaccess

只谈情不闲聊 提交于 2019-12-17 04:01:26
问题 I've been trying all sorts of solutions from this site and none seem to work. I'm currently hosting with hostgator. This is my current .htaccess file: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php/$1 [L] </IfModule> <IfModule mod_suphp.c> suPHP_ConfigPath /home/user/php.ini <Files php.ini> order allow,deny deny from all </Files> </IfModule> This is in the root folder of my site. I have also tried

How to force https on elastic beanstalk?

无人久伴 提交于 2019-12-17 02:56:15
问题 I can't seem to force https on the free usage tier of elastic beanstalk. I have tried the following suggestion at How to force https on amazon elastic beanstalk without failing the health check Using this Apache rewrite rule RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{REQUEST_URI} !^/status$ RewriteCond %{REQUEST_URI} !^/version$ RewriteCond %{REQUEST_URI} !^/_hostmanager/ RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R] When I try that, http requests