mod-rewrite

Remove index.php from URL in Codeigniter

好久不见. 提交于 2019-12-18 16:35:14
问题 I have done this lots of time. But than also I am stuck here again (in a different server) and can not figure out what is the issue. Completed htaccess editing <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /glt.me/CI/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /glt.me/CI/index.php/$1 [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule> rewrite module is enabled (as per customer care perons says) Error :

How to access directory's index.php without a trailing slash AND not get 301 redirect

时间秒杀一切 提交于 2019-12-18 14:53:35
问题 I have this structure: site.com/api/index.php . When I send data to site.com/api/ there is no issue, but I imagine it would be better if the api would work without the trailing slash also, like this: site.com/api . This causes a 301 redirect and thus loses the data (since data isn't forwarded). I tried every re-write I could think of and couldn't avoid the redirect. This is my current re-write rule (though it may be irrelevant). RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST

What is the best way to clean a string for placement in a URL, like the question name on SO?

寵の児 提交于 2019-12-18 13:39:14
问题 I'm looking to create a URL string like the one SO uses for the links to the questions. I am not looking at rewriting the url (mod_rewrite). I am looking at generating the link on the page. Example: The question name is: Is it better to use ob_get_contents() or $text .= ‘test’; The URL ends up being: http://stackoverflow.com/questions/292068/is-it-better-to-use-obgetcontents-or-text-test The part I'm interested in is: is-it-better-to-use-obgetcontents-or-text-test So basically I'm looking to

mod rewrite directory if file/folder not found

不羁岁月 提交于 2019-12-18 13:29:20
问题 I have a folder named "folder1" in my root directory www.domain.com/ www.domain.com/folder1 I need to redirect all the requests to www.domain.com that turn up to be a 404 error, to folder1. Like so: www.domain.com/a_file.txt If a_file.txt doesn't exist, look in folder1: www.domain.com/folder1/a_file.txt I want this to work the same for subdirectories, like so: www.domain.com/a_folder (redirect if it doesn't exist in the root) www.domain.com/folder1/a_folder I know I should use RewriteCond %

.htaccess rewriterule not working correct on mac

一世执手 提交于 2019-12-18 13:24:22
问题 I have a website project on my mac book pro leopard, and I am using built in apache2 and php. I've made my configurations in both httpd.conf and user.conf to use htaccess. Changes done like : LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so <Directory > AllowOverride All </Directory> The problem is when i want to open a site like localhost/~username/site/site/index.php/welcome, index.php does some operations and finds the right controller and the right page. But when I try to

mod_rewrite: add trailing slash?

强颜欢笑 提交于 2019-12-18 13:14:26
问题 I am using a .htaccess file to direct requests for a directory to a custom php file that provides info about that directory (and i want the url displayed by the browser to not change). Here is the relevant part of the .htaccess file. RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)$ /myphp.php?url=%{REQUEST_URI} [QSA,L] This works well if you go to a directory and include a trailing slash: http://domain.com/path/ But without the trailing slash, it doesn't http://domain.com/path The url

PHP root with .htaccess

随声附和 提交于 2019-12-18 12:43:25
问题 I'm using 000webhost, which uses a public_html folder in the root folder as the visible root for the site. In that folder, I have an assets folder with some PHP scripts, and other folders with PHP index pages. Using require "/assets/includes/scriptname.php"; does not work, as it tries to find a sibling folder to public_html. I'm allowed to edit .htaccess to change the root folder relative to the PHP lookup, but I don't know how. File tree: public_html (within root, but simulated root) folder1

.htaccess rewrite subdomain to directory and keep subdomain in url

断了今生、忘了曾经 提交于 2019-12-18 12:33:09
问题 I need to rewrite a subdomain to a subdirectory using .htaccess but keep the subdomain in the url like this: Visited url in browser: sub1.domain.com Served url: sub.domain.com/sub1/ I tried the following RewriteCond %{HTTP_HOST} ^subdomain.domain.com RewriteRule ^(.*)$ http://subdomain.domain.com/subdomain/$1 [L,NC,QSA] but this leads to an endless loop. I know that it would be easier to do this by php but is there any solution for this with using .htaccess? 回答1: You can use this rule in

A tool to debug and test mod_rewrite (.htaccess) directives [closed]

只谈情不闲聊 提交于 2019-12-18 12:19:38
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . Although being a decent web developer, I and most of my colleagues always struggle with basic tasks when using mod_rewrite. I read the manuals and understood most of it, however most skills I've learned in life are by doing. The trouble is, there's no easy way to debug the configuration . Most of the time if I

How to Redirect to a url containing an anchor (#)?

会有一股神秘感。 提交于 2019-12-18 12:02:08
问题 I need to take standard incoming urls and rewrite redirect them to target specific anchors on a single page (incoming html page name becomes the anchor name). E.g., the rule would be like this: RewriteRule ^files/([a-zA-Z0-9\-_]+)\.html$ /test.html#$1 [R] So this url: http://foo.com/files/bar.html ...would become: http://foo.com/test.html#bar The rule itself works fine, but the # character gets encoded in the browser address bar to: http://foo.com/test.html%23bar which of course does not work