mod-rewrite

.htaccess rewrite /foo/bar/ to /foo/bar.php

岁酱吖の 提交于 2019-12-23 00:29:21
问题 I'm looking to set rules in my .htaccess file so that all files with a .php extension can be accessed by replacing the extension with just a slash ( /foo/bar/ would silently load /foo/bar.php ). Previously, I found this, which is kind of what I'm looking for, except it only changes /foo/bar.php to /foo/bar (notice there is no end slash). I'm almost a completely newbie when it comes to htaccess, and about 30 minutes of tweaking with the code from the previous link produced nothing by a ton of

math with regexp in mod_rewrite

痞子三分冷 提交于 2019-12-22 23:47:13
问题 I'm trying to do the following: I have the url: http://www.example.com/9999 and I want it to subtract 5000 from that number, and seamlessly redirect to: http://www.example.com/page.php?id=4999 Can regular expressions in mod_rewrite do maths? 回答1: No. There is no math in regexp. 回答2: There might not be math in regexp, but what I needed was perfectly doable: Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteRule ^5([0-9][0-9][0-9])($) /offer_details.php?offers_id=$1$2 [R]

htaccess not rewriting url for my GET requests

Deadly 提交于 2019-12-22 22:19:46
问题 I am using the following url to bring in all my page templates: www.example.com/tournament/index.php?view=* I want to rewrite this to www.example.com/tournament/* so www.example.com/tournament/index.php?view=profile becomes www.example.com/tournament/profile and www.example.com/tournament/index.php?view=profile&id=testUser becomes www.example.com/tournament/profile/testUser . I currently have tried: RewriteRule ^tournament/([^/]*)/([^/]*)$ index.php?view=$1&id=$2 RewriteRule ^tournament/([^/]

Remove file extensions from urls

痞子三分冷 提交于 2019-12-22 18:19:32
问题 I've never used mod_rewrite but i want to remove all file extensions from my urls for a website. What is the rule that i would need to do this? I've tried this, but that gives me an internal error every time i click a link on my website RewriteRule ^(.*)$ $1.php [L] 回答1: What you want to do is first check if the file exists, this will prevent the infinite loop that is causing the 500 error. It will also make other non-php file requests work (ie: images, css, etc). RewriteCond %{REQUEST

htaccess rewrite url like Stack Overflow

落爺英雄遲暮 提交于 2019-12-22 18:13:46
问题 Stack Overflow generates rewrite URLs, so i need to know how i can do it like Stack Overflow? http://stackoverflow.com/questions/9168364/how-to-rewrite-seo-friendly-urls-like-stackoverflow => 200 ok.(without trailing slash) http://stackoverflow.com/questions/9168364/how-to-rewrite-seo-friendly-urls-like-stackoverflow/ => 200 ok.(with trailing slash) http://stackoverflow.com/questions/9168364/ => 301 redirect. http://stackoverflow.com/questions/9168364 => 301 redirect. How i can do it with mod

Blocking specific file extension with htaccess?

六眼飞鱼酱① 提交于 2019-12-22 17:57:29
问题 I am using this code to send all the request to a single php file: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) myfile.php?id=$1 [QSA,L] But now I want to also block direct access to myfile.php and other phps. I don't want the php files to open directly via browser, but they must work for includes and such. How can I do this? 回答1: Maybe this will help: RewriteCond %{REQUEST_URI} !(.*).php$ [NC] RewriteRule ^.* - [F,L] Several nice

How do I 301 redirect one domain to the other if the first has a folder path

人盡茶涼 提交于 2019-12-22 17:52:59
问题 I want to 301 redirect from: www.olddomain.com to the root of newdomain.com but I want it to work no matter what the folder path is on the old domain. eg: the following should all redirect to the root of newdomain.com www.olddomain.com olddomain.com www.olddomain.com/folder/file.php olddomain.com/folder/file.php How can I do that with Mod Rewrite in the .htaccess file? 回答1: Try this rule: RewriteEngine on RewriteCond %{HTTP_HOST} (^|\.)old\.example\.com$ RewriteRule ^ http://new.example.com/

Apache redirects based on symlinks

旧时模样 提交于 2019-12-22 17:39:09
问题 In one app, some public image resources are symlinked to alternative names for historic reasons. For example, we might have a.png b.png -> a.png Google's PageSpeed Insight that identical content should be served from a consistent URL applies to assets like this as well as content. Rather than reorganising the assets we have in place, I would like to have Apache perform an external redirect from b.png to a.png. With mod_rewrite I can make a RewriteCond to narrow in on symbolic links: '-l' (is

URL rewriting, PHP templating and the $_GET array

别来无恙 提交于 2019-12-22 17:38:47
问题 I have an index.php file in the top level with other files such as "login.php", "register.php" in a folder called includes. The folder hierarchy looks like this: index.php includes/ register.php login.php css/ style.css images/ image.png How can I set the url to something like http://www.mydomain.com/register which then from within the index.php page calls (includes) the register.php page? Is this the best way to go about it? Thanks Mike 回答1: If your server is Apache: Create on root folder

Apache redirects based on symlinks

帅比萌擦擦* 提交于 2019-12-22 17:38:39
问题 In one app, some public image resources are symlinked to alternative names for historic reasons. For example, we might have a.png b.png -> a.png Google's PageSpeed Insight that identical content should be served from a consistent URL applies to assets like this as well as content. Rather than reorganising the assets we have in place, I would like to have Apache perform an external redirect from b.png to a.png. With mod_rewrite I can make a RewriteCond to narrow in on symbolic links: '-l' (is