mod-rewrite

How do I make a rewrite rule in php?

拥有回忆 提交于 2019-12-17 21:18:29
问题 RewriteEngine on Rewriterule ^(.*).htm $1.php This works fine when i try to access every php page But how could i make it RewriteRule ^/somepage $ /somepage.php (its not working ) if the page is about.php the url should be about/ (directory type) 回答1: If you want to use the rule in a .htaccess file, you need to remove the local path prefix from the pattern as it is removed before testing the pattern. In case of the root directory that is the / . So try this: RewriteRule ^somepage/$ /somepage

Rewriting a URL to a PHP parameter from inside a subdirectory

主宰稳场 提交于 2019-12-17 21:10:56
问题 What I'm asking for is simply rewriting any URL-given sub-directiories to a PHP URL parameter for nicer looking, user friendly URL. I know that this is possible using the Apache Rewrite Engine and associated parameters. The problem on my end is that I do not want to rewrite i.e mydomain.com/parameter -----------> mydomain.com/index.php?id=parameter But rewriting mydomain.com/subdirectory/parameter -----------> mydomain.com/subdirectory/index.php?id=parameter In my root folder I have an

How to rewrite specific urls using mod_rewrite?

社会主义新天地 提交于 2019-12-17 20:43:29
问题 I have a geoip http header named {HTTP:CF-IPCountry} that store the country code like FR, US etc.. what i need to do is to add this query string loc={HTTP:CF-IPCountry} to the website homepage https://example.com/test-website/ and to any page that has url start with https://example.com/test-website/products/ or https://example.com/test-website/shop/ and append the query string if there are any other query strings used on the url so if the user requested page https://example.com/test-website

.htaccess - Pretty User Profile URLs

谁都会走 提交于 2019-12-17 20:41:14
问题 I want to make my user profiles 'pretty' as it were. Here is the regular URL: user.php?user=UserName I want this to become: user/Username Please help :) Im a .htaccess newbie. 回答1: Try these directives: RewriteEngine on RewriteRule ^user/([^/]+)$ user.php?user=$1 [L,QSA] This rule rewrites any request with a URL path of the form /user/ foobar internally to /user.php?user= foobar . 回答2: RewriteRule ^user/(.+)$ user.php?user=$1 [L,QSA] 来源: https://stackoverflow.com/questions/930789/htaccess

Rewriting URL with .htaccess local in XAMPP

别来无恙 提交于 2019-12-17 20:36:33
问题 My .htacces begins with RewriteEngine on RewriteBase / (I tried it also without RewriteBase...) I tried all of the following rewriting rules to rewrite the URL index.php?page=news to /blog RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$ index.php?page=$1 [L] RewriteRule ^([^/]*)/blog$ /sites/blog/index.php?page=$1 [L] RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L] Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I

Trying to make a GET variable invisible in an URL but retain its usefulness using mod_write

故事扮演 提交于 2019-12-17 20:29:36
问题 Good day all, I am trying to master the ,magic of mod_rewrite and require some advice/help. I am trying to turn an URL from: http://www.domainname.com/preview/about/5 To this: http://www.domainname.com/preview/about The issue is, I still need to retain the [id] part of the original URL to be used as a GET later on and it not be visible. The code I have thus far: RewriteRule ^preview\/([^/]+)\/([^/]+)\/$ /preview\/$1?id=$2 [R=301,QSA] RewriteRule ^preview\/([^/]+)\/$ ?mode=preview&id=$2 [L,QSA

.htaccess redirect if file doesn't exist

无人久伴 提交于 2019-12-17 20:11:31
问题 So here's what I'm trying to do. I have a simple framework and I am using mod rewrite to rewrite the urls so that they point to the correct files. I have a process folder which sits inside the web folder (the web folder is where all the actual website files like images, css, etc are). This works great but what I am trying to do now is to have a default.php file to process the forms. The file works great if I point the form to it but I want to be able to point the form to it's proper file and

Rewriting dynamic URLs

房东的猫 提交于 2019-12-17 20:09:07
问题 I' trying to rewrite 1 dynamic URL to another dynamic URL as follows; /category?category=News to /categorysearch/result/?q=news I was wondering if anyone had an idea on how this can be done in htaccess? Thanks. 回答1: So the final EDITED solution is (for your linked .htaccess): RewriteCond %{REQUEST_FILENAME} ethical [NC] RewriteCond %{QUERY_STRING} (^|&|%26|%20)ethical(=|%3D)([^&]+) [NC] RewriteRule .* /catalogsearch/result/?q=%3 [L,R] If I use the 'category' terms like in this current

.htaccess for friendly URL with multiple variables

人盡茶涼 提交于 2019-12-17 19:53:36
问题 I am working on making my site more SEO friendly I am currently using RewriteEngine On RewriteRule (.*)$ index.php?page=$1 To turn site.co.uk/index.php?page=page_name into site.co.uk/page_name I want to also use this for sub pages too. I have tried this: RewriteEngine On RewriteRule (.*)/(.*)$ index.php?page=$1&subpage=$2 but its not working, it runs site.co.uk/page_name/sub_page but when you go to site.co.uk/page_name it returns the 404 not found. I want it to run site.co.uk/page_name and it

htaccess RewriteRule page with query string

给你一囗甜甜゛ 提交于 2019-12-17 19:22:46
问题 I have a set of pages that I'm trying to redirect to new URLs. They have different query strings in the target URL than in the original URL. http://localhost/people.php?who=a should redirect to: http://localhost/people/?t=leadership And on and on... I have the following set of rewrite rules and am obviously doing something very wrong. RewriteRule ^people.php?who=a /people/?t=leadership [R=301,L] RewriteRule ^people.php?who=f /people/?t=faculty [R=301,L] RewriteRule ^people.php?who=p /people/