I am not sure if my .htaccess is wrong or if the server didn't read my .htaccess file yet - .htaccess

I am pretty certain, that my code is alright, for a briefly moment, my htaccess seems to work when i entered an url. After I extended the file and reuploaded it, my Rule didn't work any more. Even when I removed my edit the Rewrite Rule don't triggert any more.
Did i miss something in my Rule. I don't get it whats wrong right now.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^www\.sub\.domain\.de\/(.*)\.html$ www.sub.domain.de/typo3/$1.html?&%{QUERY_STRING}
</IfModule>

Okay. My first mistake was the complete url as first param in RewriteRule.
After I followed Kaddath's instuctions the rewrite kinda worked. I still had a problem with a loop call. The htaccess appendes planty "typo3/typo3/...", so that a RewriteCondition has to solve this. I checked if the url has already typo3 in his string. Now the Url is correctly rewritten.
I also tried [L] before to stop a looping rewriteRule, but it didn't help.
Thank you Kaddath for giving the right clues.

Related

How to rewrite directories into query string

Yay, my first Stackoverflow question ever! Been around for years but this one gets me.
I have an URL:
https://example.com/site.com/phpBB3/general-f1/things-are-getting-crazy-here-t948-60.html
(I need to test this locally first which is why I have set it this way)
I want to change the URL into:
https://example.com/site.com/phpBB3/viewtopic.php?f=1&t=948&start=60
I have my .htaccess file in /example.com/.htaccess and the content is:
RewriteEngine On
RewriteRule ([a-z0-9_-]*-f)([0-9]+)\/([a-z0-9_-]*-t)([0-9]+)(-([0-9]+))?\.html$ viewtopic.php?f=$2&t=$4&start=$6 [QSA,NE,L,NC]
I have AllowOverRide set and the rewrite mod is enabled.
This seems to work in https://htaccess.madewithlove.be/
but not at the actual site. I'm going crazy. What's wrong with me?
This helped me to solve my problem https://techtitbits.com/2008/10/phpbb-redirect-broken-links-after-uninstalling-an-seo-mod/

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";

Stop mod_rewrite returning REQUEST_URI when (.*) is empty

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^mocks/site/(.*)$ http://thelivewebsite.com/$1 [R=301,L]
That is my htaccess file's contents.
The htaccess file is in the root directory of the hosting account and I just want to redirect the directory mocks/site/ to the new domain (with or without any extra directories).
eg: if someone goes to http://mywebsite.com/mocks/site then it needs to redirect to http://thelivewebsite.com. If they go to http://mywebsite.com/mocks/site/another/directory then it needs to redirect to http://thelivewebsite.com/another/directory. I hope that makes sense.
So the problem I have is that the htaccess code above seems to work pretty well when there is something after mocks/site/ however when there isn't something after that then the $1 in the redirect seems to reference the whole REQUEST_URI (eg: mocks/site/ rather than nothing - as there is nothing after it).
I don't know how to stop this. I thought about using a RewriteCond, but I'm not sure what to use there. I can't find anything that helps me to determine if there is anything after mocks/site/ or not.
Any help will be much appreciated.
Thank you.
That's very strange behaviour -- never seen anything like that. Therefore I think it could be something else (another rule somewhere -- on old or even new site). I recommend enabling rewrite debugging (RewriteLogLevel 9) and check the rewrite log (that's if you can edit Apache's config file / virtual host definition).
In any case, try this combination:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^mocks/site/$ http://thelivewebsite.com/ [R=301,L]
RewriteRule ^mocks/site/(.+)$ http://thelivewebsite.com/$1 [R=301,L]
It will do matching/redirecting in 2 steps: first rule is for exact directory match (so no $1 involved at all) and 2nd will work if there is at least 1 character after the /mocks/site/.
Alternatively (Apache docs even recommending this one) use Redirect directive (no need for mod_rewrite at all for such simple redirects):
Redirect 301 /mocks/site/ http://thelivewebsite.com/

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