mod-rewrite

My htaccess RewriteRule works on localhost/mysite but not at mysite.com on a 1&1 shared host

旧巷老猫 提交于 2019-12-31 00:47:07
问题 Solved: unfortunately, the solution is not a satisfying one. This morning, when trying @Wige's Suggestion, I found, to my suprise, that the Expected values WERE infact sent to the page as a GET query. Apparently, 1&1 (who I know have been making changes to their environment this last couple weeks), did something behind the scenes which magically fixed my problem, and now all of my previously unworking code is working as originally expected. New info : The Apache version of the production

Rewriteengine in .htaccess to catch files not ending in html

↘锁芯ラ 提交于 2019-12-30 22:29:27
问题 I'd like to use mod rewrite in to convert web page addresses like /directory to /directory/index.html , in a standard LAMP hosting situation. What I have works for addresses that end in a slash. I can't find a way to handle addresses that don't end a slash . What seems like it should work is: rewriterule ^(.*)/$ $1/index.html [L] /* addresses ending in / */ rewriterule ^(.*(?!html))$ $1/index.html [L] /* where the problem is */ But the second line causes a 500 server error. If I add a single

Redirect non-www and non-https to https://www

泪湿孤枕 提交于 2019-12-30 12:13:47
问题 I want to redirect non-www and non-https URLs to https://www for my domain, I actually have the following htaccess, that works ok redirecting non-https to https but still allows to access domain.com without www, RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI}%{QUERY_STRING} [L,R] # Redirect Trailing Slashes... RewriteRule ^(.*)/$ /$1 [L,R=301] # Handle Front Controller... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f

Apache Mod Rewrite for Pretty URLs isn't working

谁说我不能喝 提交于 2019-12-30 11:21:23
问题 I'm trying to figure out how to do an apache mod_rewrite to remap $_GET . What I'm trying to accomplish: Currently, to get to the page one would have to go to http://www.domain.com/index.php?URL=pages/the-page.php I would like this to work in 2 ways: If someone goes to domain.com/the-page , it takes them to the above but keeps it looking like this. Secondly, if someone goes to the http://www.domain.com/index.php?URL=pages/the-page.php , it will still show as domain.com/the-page , keeping the

Rewrite URL to index.php but avoid index.php in the URL

↘锁芯ラ 提交于 2019-12-30 11:14:10
问题 I'm trying to internally redirect all requests to index.php and externally redirect all requests that contain index.php using a .htaccess file. So URLs like http://host/test should be processed by index.php and URLs like http://host/index.php/test should be redirected to http://host/test and then processed by index.php (without redirecting the browser to index.php) I tried the following but always get a message "Too many redirects...": RewriteRule ^index\.php/?(.*)$ /$1 [R,L] RewriteRule .*

Query string redirection with htaccess

こ雲淡風輕ζ 提交于 2019-12-30 10:30:13
问题 On a website I'm working on now I need to set up a redirection that takes a query string into consideration. Example: http://www.domain.com/?id=86&name=John&ref=12d34 -> http://www.domain.com/?ref=12d34 http://www.domain.com/?ref=593x56&id=935 -> http://www.domain.com/?ref=593x56 http://www.domain.com/?ref=3v77l32 -> http://www.domain.com/?ref=3v77l32 So basically I need to find the ref parameter and it's value (whatever it's length) and append only that part to the new URL. The issue is the

Cleaning up nested mod_rewrite statements

坚强是说给别人听的谎言 提交于 2019-12-30 10:18:27
问题 I am cleaning up a large .htaccess file containing a lot of mod_rewrite statements. The biggest part of the clutter comes from statements catching various occurrences of /directory1 /directory1/directory2 /directory1/directory2/directory3 using statements like RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)$ RewriteRule .* /front.php?level1=%1&level2=%2&%{QUERY_STRING} [L] RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)$ RewriteRule .* /front.php?level1=%1&level2=%2&level3=%3&%{QUERY_STRING

Using custom environment variables in .htaccess

烂漫一生 提交于 2019-12-30 10:14:20
问题 I need something like this: SetEnv foo bar.baz RewriteEngine On RewriteCond %{HTTP_HOST} ^%{foo}$ RewriteRule ^(.*)$ http://www.foo/$1 [L] UPD: I have made as follows: SetEnv HOSTNAME_ENV testsite RewriteEngine On RewriteCond %{HTTP_HOST} ^%{ENV:HOSTNAME_ENV} RewriteRule ^(.*)$ http://www.%{ENV:HOSTNAME_ENV}/$1 [L,R=301] But it doesn't work. %{ENV:HOSTNAME_ENV} is not defined. 回答1: This won't work, because mod_rewrite does not expand variables in test patterns. Consequently, your expression

mod-rewrite redirect but prevent direct access

北慕城南 提交于 2019-12-30 09:59:53
问题 I want to redirect all content to: www.example.com/public/... but prevent direct access to www.example.com/public/file1/ www.example.com/public/file2/ etc The final URL should be: www.example.com/file1/ I've tried this for redirecting and it works - but I dont know how to prevent direct access: ReWriteCond %{REQUEST_URI} !/public/ RewriteRule ^(.*) public/$1 [L] 回答1: After spending an inordinate amount of time trying to solve this problem, I found that the solution lies with the under

mod_rewrite problem with relative path css/js

心已入冬 提交于 2019-12-30 08:53:39
问题 Hi I have a problem. I want to get all requests to redirect to index file in main directory and I've achieved this but there are problems with relative paths. When I put address like: mydomain.com/something it works ok as the paths are relative to the main directory. The problem is when I put something like: mydomain.com/something/somethingelse. the .htaccess file: Options FollowSymLinks RewriteEngine On # ignore anything that's an actual file RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f #