Htaccess - pass case sensitive subdomain to errorpage - .htaccess

Im not very familiar with .htacces and conditions and rules.
So far i have obviously failed to understand it. - Solution might be simple and straigth forward.
I have looked through posts and lots of google searches, and now im here posting my question.
I am doing a project where case sensitive ticker-code can be send to my site, as follows:
Examples:
This works: mydomain.com/LeUj
This works: mydomain.com#LeUj
This does not: LeUj.mydomain.com
The ticker-code is send to my errorpage, but it is forced to lower-case, which not works with my service.
Any help is really appreciated.
Thanks
My .htaccess file so far:
ErrorDocument 404 /4_nul_4.php?url=%{REQUEST_URI}
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.mydomain\.com$
RewriteRule !^4_nul_4\.php?url=%{REQUEST_URI}$ 4_nul_4\.php?url=%{REQUEST_URI} [L]

Related

Internal rewrite to remove directory from url with htaccess

I've searched and tried many tutorials and problem solutions but couldn't achieve what I want.
If user open domain.com/xxx.php he see the content of domain.com/hosting/xxx.php
This
RewriteRule ^xxx.php$ /hosting/xxx.php
Works perfectly what i want to do, but there are over 150 pages in hosting directory and writing rules for each page does not seem right? any possible way to do it dynamically?
I tried this solution it works but it try to find those pages which are currently at root domain.com/xxx.php inside domain.com/hosting/
I search slimier questions have been asked many times before but non of the answer worked for me.
You need to also take care of reuests to the shortened, rewritten URL:
RewriteEngine on
RewriteRule ^/?hosting/(.*)$ /$1 [END,NC,R=302]
RewriteRule ^/?(.*)$ /hosting/$1 [END]

Set an index page for a specific folder in .htaccess

What I want to do should be quite simple: when the admin writes www.example.com/admin I want that he's addressed to www.example.com/admin/admin_index.php.
I wrote this rule and I checked on other posts here on Stackoverflow: it apparently seems to be correct, but it actually doesn't work.
RewriteEngine On
RewriteRule ^/admin/?$ /admin/admin_index.php [L,NC]
Has anyone any clue on why the redirect doesn't work, since it "stays" at www.example.com/admin outputting (obviously) the 403 error?
There is no need to use a rewrite rule. Just use DirectoryIndex directive in admin/.htaccess:
DirectoryIndex admin_index.php
This will load admin/admin_index.php when a request comes for http://domain.com/admin/

.htaccess rewriterule problems

I need a few redirects in my .htaccess file, and what I've done works perfectly well in the htaccess tester, but it doesn't work at all on my server. I've spent days finding a solution, and I'm stuck. It would be wonderful if someone could help!
1) "/-" in URLs
This is a good example:
https://www.haraldjoergens.com/galleries/remembrance-sunday/2012-cenotaph/-march-past/index.php?page=40
The "2012-cenotaph/-march-past" is supposed to be "2012-cenotaph-march-past"
I had though a straightforward RewriteRule ^(.*)/-(.*)$ %1-%2 [R=301,L] would do the trick, but it seems to be completely ignored.
2) Repetition needs to be removed:
Due to making the "Replace" a 301 replace too early, the search engine bots try to access very wrong things:
https://www.haraldjoergens.com/galleries/rowing/index.php/galleries/rowing/
The second "/galleries/rowing" needs to be removed. My attempt via
RewriteRule ^(.+/index\.php)/.*$ /$1 [R,L]
works fine in htaccess tester, but seems to send the website into an endless loop.
Any suggestions would be really appreciated!
Thanks!!!
Harald
htaccess example
I dont know if this is what you really need.
One thing helps me is to change the routes for example:
$route['index.php/galleries/rowing/'] = "index.php";

htaccess from old forum url to new one

until now I have always used htaccess to rewrite URLS in order to have non-SEF url to SEF urls.
Today I am facing a new challenge that honestly, beeing non confident in regular expression, I really don't know how to achieve.
I have a situation where a forum on a website of mine has been update in the following form:
previous link: www.domain.com/forum3/topic/name-of-topic/post/7548
new link: forum.domain.com/Topic-name-of-topic/
How do I intercept /post/37764 string and tell htaccess to not consider it?
And how to instruct the server to build that kind of url instead of the provious. I am very confused about it.
Any suggestion? Thank you very much. Is there any resource that I can read to help me better understand the case?
Thanks again.
EDIT
Florian answer is correct. I just added few mods to fit it better.
RewriteEngine On
#RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
RewriteRule ^forum3/topic/([^/]+)-[0-9]+$ http://forum.domanin.com/Topic-$1/ [L,R=301]
You can try this code :
RewriteEngine On
RewriteBase /
RewriteRule ^forum3/topic/([^/]+)/post/[0-9]+$ /Topic-$1/ [L,R=301]
/([^/]+)/ means that we want to catch a string containing one or more characters except / preceded and followed by a /.
This link might help you to test your .htaccess files :
Test your apache htaccess files online

Friendly URLs with .htacces NOT working... and stackoverflow URLs style

I know this question has been asked a million of times here at stackoverflow, but I cant get it to work so I need someone who knows to finally resolve this problem!
I want that when this is inserted in the URL:
http://website.com/pelicula/0221889/
http://website.com/pelicula/0221889/posters/
It really goes to this:
http://website.com/index.php?ctrl=pelicula&id=0160399
http://website.com/index.php?ctrl=pelicula&id=0160399&tab=posters
This is how my .htacces file looks like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/([^/]+)/([^/]+)/?([^/]*)/?$ index.php?ctrl=$1&id=$2&tab=$3 [QSA,L]
</IfModule>
But its not working! I just get a 'Not found' error in my web server (only when using the friendly URL, regular is still working fine). How to fix this?
I would also want to know how to be able to add anything at the end of the URL without getting any errors (like stackoverflow URLs).
Like this:
http://website.com/pelicula/0221889/any-text-i-want-to-put
http://stackoverflow.com/questions/3033407/htacces-to-create-friendly-urls-help-needed
I hope someone can give me an answer, thanks!
I read all of your threads so I'm not going to reiterate what others have said or asked. I'm just throwing out ideas here but...
Sounds like rewrite is working - it's actually redirecting correctly - but it's pointing you to a page that is not found. Have you tried using RewriteBase?
RewriteEngine On
RewriteBase /

Resources