Shorter URL Address via .htaccess file - .htaccess

My address is
http://myadress.com/central/threads/edit?topic=3
and I want this
http://myadress.com/central/threads/edit/3
Can someone help me with this? I tried a lot of solutions, but they dont work for me. The number 3 is only example, It can be 5,6 or any number.
One of the solutions is
RewriteRule ^central/threads/edit/([^/]*)$ /central/threads/edit?topic=$1 [L]
but its not working.. when i go to
http://myadress.com/central/threads/edit/4
it redirects me to
http://myadress.com/central/threads/edit/4.php
!SOLVED! The code is working.. its must be at the top of the .htaccess
RewriteRule ^central/threads/edit/([^/]*)$ /central/threads/edit?topic=$1 [L]
Im dumb, i dont tried to place the code at the top of .htaccess...
(Sorry for my english..)

Related

htaccess: rewrite to optional amount of "subfolders" www.xyz.com/a/b/c/d

sorry for my bad english and wrong use of technical terms.
So I got these links on my site:
www.xyz.com/index.php?link=abc
I want to rewrite via htaccess like this:
www.xyz.com/def/.../jki/abc
/.../ meaning that I want to be able to be as flexible with my "link-design" as I want.
I tried it this way:
RewriteRule ^.+/([a-z-.-?]+) index.php?link=$1 [NC,L]
and it works, but the strange part is, that it doesnt work all the time, or it totally stops working. Sometimes images and css is not being loaded anymore.
Then I switched to test it with
RewriteRule ^.+/m/([a-z-.-?]+) index.php?link=$1 [NC,L]
and this works fine, but I'm abviously stuck with the /m/-part like:
www.xyz.com/def/.../jki/m/abc
Is there even any option to do this?
Thank you very much.

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

The requested URL /public_html/ was not found on this server

I'm working on a local MAMP website. I use a micro MVC framework to use friendly urls
so I don't need to call index.php (which is inside of public_html directory) in the urls.
To achieve that, I have the following htaccess:
RewriteEngine on
RewriteCond %{REQUEST_URI} !public_html/
RewriteRule (.*) /public_html/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
Then I have the following line in /etc/hosts
127.0.0.1 mywebsite
Also, I have the following in httpd.conf
<VirtualHost *>
DocumentRoot "/Applications/MAMP/htdocs/mywebsite"
ServerName mywebsite
</VirtualHost>
So if I simply call http://mywebsite from the browser, the whole thing works smoothly.
So what's the problem?
The problem appears if I try to reach the same page from another machine in my LAN.
So if I write http://192.168.1.15/mywebsite the answer is:
Not Found
The requested URL /public_html/ was not found on this server.
I get the same message if I call http://localhost/mywebsite from my own machine.
I have the feeling that is something related to .htaccess, but I've been trying a
lot of different ideas I've found in the web, and nothing works.
I'd like to fix this, because I need other people to check the website from their machines.
If you have any clue please help. Thanks a lot.
Edit: I can't solve this, so as a temporary fix I've created a free account at AppFog for my team to be able to access the page until we go to production.
After all these years, I thought that computing would be easier... it's getting harder, actually. The htaccess file is a huge mistery to me! Thanks anyway :)
By the way... as I told you, I've found a way to fix the problem. The funny thing is I have to use a different .htaccess file. I thought you could be interested, provided that it seems you like computing stuff :)
This is the .htaccess that works in my LAN debian server:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/(www/.*)$
RewriteRule ^(.*)$ index.php [QSA,L]
As you can see, it's different from the one I showed you at my first post. My conclusion? Well, even when I always try to keep things simple, life shows me one and another time that everything can be more complicated. Look at the .htaccess file. It's so funny... I've learnt to work with it by using different combinations of code.
Isn't it crazy? Yes it is. Please let's do understandable software. Thank you!
Ok, I've been trying a lot of different things and all of them fail. The only solution I've found is to install the web site in a separated LAN debian server. Everything works ok in that way, but it's not possible to make it work from my machine with MAMP.
Why not? Well, I don't know. After a lot of years in computing, I've learnt to say "I donĀ“t know", you know what I mean.
I've been working for a few days with an AppFog account for free but, you know, that thing cannot work when you put a database and the whole thing there. Obvious.
So at the end the only solution I've found has been to put everything at that local LAN debian server.
Thank you anyway :)

.htaccess RewriteRule help

I have been able to change the 'location' of my images with RewriteRule, but I have 3 lines of code to do this because of subdirectories in the image folders
RewriteRule ^images/([^/]+).(jpg|jpeg|bmp|gif|png)$ /includes/images/$1.$2
RewriteRule ^images/([^/]+)/([^/]+).(jpg|jpeg|bmp|gif|png)$ /includes/images/$1/$2.$3
RewriteRule ^images/([^/]+)/([^/]+)/([^/]+).(jpg|jpeg|bmp|gif|png)$ /includes/images/$1/$2/$3.$4
However, I would like to be able to not need to add to these if I ever add any deeper subdirectories.
I have tried many different approaches to this with no luck, and the following is what I am stuck with atm.
RewriteRule ^(images)(/?[^/])+(.jpg|.jpeg|.bmp|.gif|.png)$ /includes/$&
Does anyone have any ideas on how to get this code to work??
Also, is there any way to view the URL that is being used server-side?
Perhaps I'm missing something, but I don't see any reason that you couldn't simply do:
RewriteRule ^images/(.+)\.(jpg|jpeg|bmp|gif|png)$ /includes/images/$1.$2

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