mod-rewrite

Rewrite GET Query String using .htaccess

久未见 提交于 2019-12-20 03:03:40
问题 I want to Rewrite my GET Query String from this - http://www.example.com/verify.php?key=547b52f2b5d20d258e62de1e27b55c to this http://www.example.com/verify/547b52f2b5d20d258e62de1e27b55c I am using the following rule but it does not seem to work - RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(([A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ $1.php RewriteRule ^[A-Za-z-]+/([A-Za-z0-9-]+)/?$ verify.php?key=$1 [NC,L] 回答1: Use the following:

Apache/Mod Rewrite: Route everything to index.php?

走远了吗. 提交于 2019-12-20 02:57:26
问题 I'm writing a front-controller that will handle page requests, by parsing $_SERVER['REQUEST_URI']. I would like to get all requests routed to /index.php Some examples as follows: example.com/page2?foo=bar example.com/page2/?foo=bar example.com/page/action/123/ example.com/page/action/123 What is the regexp rule that i have to write in .htaccess ? And do I need an extra rule so that example.com/images/ directory would work as 'normal' directory? 回答1: You could try something like this :

htaccess rewrite if file not exists in cache folder

孤街醉人 提交于 2019-12-20 02:52:16
问题 I want to check if file is not exist in the cache folder, than rewire it to a php file. RewriteCond %{DOCUMENT_ROOT}/cache/$0 !-f [NC] RewriteRule ^([^.]+\.(jpg|png|gif|css|js))$ include/cache/optimizer.php?file=$1&type=$2&c=$0 [L,QSA,NC] eg1 : example.com/images/logo.jpg to check from example.com/cache/images/logo.jpg eg2 : example.com/images/user/user1.jpg to check from example.com/cache/user/user1.jpg eg3 : example.com/css/style.css to check from example.com/cache/css/style.css Please help

htaccess clean URL's what's the best way to do it?

末鹿安然 提交于 2019-12-20 02:51:06
问题 I'm working on clean Url's for my website and I noticed that what you find on the internet is pretty much about rewriting your clean urls to the url that your server can work with. So something like this: www.domain.com/profile/username --> www.domain.com/profile.php?u=username RewriteEngine On RewriteRule ^profile/(.*)$ /profile.php?u=$1 [L] So now with this I should link within my website to the cleanurl's. But intuitively it feels more solid/better to link to the 'dirty' url. So in that

Htaccess, redirect if folder exists

吃可爱长大的小学妹 提交于 2019-12-20 02:46:30
问题 I'm trying to redirect the user if the folder install exists but i had no luck so far. Below is my htaccess file. RewriteEngine On RewriteBase /enc/project/ # If the setup directory exists in the document root... RewriteCond %{DOCUMENT_ROOT}/install -d # ...and you're not in isntall.. RewriteCond %{REQUEST_URI} !(install) [NC] # ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect. RewriteRule ^(.*) /install [L,redirect=302] # ...rest of

HTTP headers for jpg files after mod_rewrite

只愿长相守 提交于 2019-12-20 02:37:13
问题 I'm using Apache's mod_rewrite to route requests for JPG files to a directory outside my web root. It generally has been fine, but there are a few images that do not display. I then realized that when I use PHP's get_headers() function on my image URLs, they are all returning Content-Type: text/html; charset=UTF-8 instead of the proper image/jpeg header types. I have tried explicitly setting the Content-Type: image/jpeg header and still, none of my images return the correct headers - although

301 redirect non-www to www not always working

跟風遠走 提交于 2019-12-20 01:40:50
问题 I've read through a ton of posts and pages trying to figure this out. I have it mostly working. I have a .htaccess file setup and I'm trying to redirect (301) any page in my site from non-www to www version. RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] It seems to work from the base url. However, it doesn't redirect for sub pages. This works: example.com -> www.example.com This does NOT work: example.com/foo.html -> www

Redirect all but one file in a directory via httpd.conf / htaccess

夙愿已清 提交于 2019-12-20 01:34:34
问题 I would like to redirect as such... http://old.com/a/b/ -> http://new.com/y/z/ http://old.com/a/b/file.php -> http://new.com/y/z/ http://old.com/a/b/c/file.php -> http://new.com/y/z/ http://old.com/a/b/anything -> http://new.com/y/z/ http://old.com/a/b/EXCLUDE.php -> http://old.com/a/b/EXCLUDE.php I currently have the following in httpd.conf and it redirects correctly: RedirectMatch 301 /a/b/(.*) http://new.com/y/z/ I don't know how to exclude one file from being redirected. Basically I want

Simple .htaccess subdomain rewrite

做~自己de王妃 提交于 2019-12-19 20:34:10
问题 I know there is a lot of questions on here about this... but right now I feel like a deer stunned by oncoming headlights... I just don't know where to start and which option to choose. My requirements are simple. User goes to http://application.domain.com or http://www.application.domain.com and the real location of these files is http://www.domain.com/application Obviously this needs to be done using wildcards so that any domain (even if it doesn't exist) triggers the rewrite. I hope this

htaccess 301 redirect entire site but with exceptions

ⅰ亾dé卋堺 提交于 2019-12-19 18:28:13
问题 I am trying to create an htaccess file to redirect my entire site except with some exceptions, but I can't get it working. I need to redirect the entire thing, provide a specific redirect, and exclude two pages. Below is my non-working sample. Thanks! RewriteCond %{REQUEST_URI} !^/events/index.html RewriteCond %{REQUEST_URI} !^/calendar/index.html Redirect 301 /info/faq.html http://mynewsite.com/my-page Redirect 301 / http://mynewsite.com 回答1: You're attempting to mix mod_rewrite with mod