URL Rewriting using mod_rewrite - .htaccess

i'm trying lear to make a simple url rewrite and can't understand why is not working.
I created the file .htaccess with this:
RewriteEngine On
RewriteRule ^section\.php$ /how-does-it-work/ [R]
All i want to do is /section.php be displayed as /how-does-it-work/
i'm following a tutorial but doesn't seem to work.
Nothing seems to work… i even tried a mod_rewrite generator, i'm using GoDaddy, is there anything i should activate or something? 'cause so far i'm only dealing with the .htaccess file.
Thanks

You are using them the wrong way around. Try:
RewriteRule ^how-does-it-work/?$ /section.php [L]

Related

How to use .htaccess redirect

Okay, so I here .htaccess redirect is a pretty big deal, but I dont know how to do it. Honestly I'm a n00b, so can someone tell me how this is even accomplished? So far I know you have to have a page called
example.com/example.html
and then you want it to look like this:
example.com/example/
My problem is, how do you do that?
That can be achieved by adding the following to your htaccess
RewriteEngine On
RewriteRule ^(.*).html$ /$1/ [R,L]
The above will change any page with a html extension to FILEANME/

How to remove middle part from URL - mod_rewrite

How to rewrite this url "www.domain.com/index.php?route=custom/static/page" to "www.domain.com/page" in htaccess file, basically just want to take out index.php?route=custom/static/ from urls.
I don't know regex so I tried http://www.generateit.net/mod-rewrite/, but it only generates
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
which doesnt remove 'custom/static' from URLs, I tried a few other examples as well but only removes index.php? and doesnt pass variable, any help is appreciated.
Do you know the concept of using mod-rewrite?
In your question you have mentioned to use mod-rewrite to redirect
"www.domain.com/index.php?route=custom/static/page",
Here $_Get['route']="custom/static/page"] $url_parameter=$_Get['route']
to
"www.domain.com/page" [here $_Get['route']="page"],
So now you can mannually add "custom/static/" to the obtained value of $_Get['route']. as $url_parameter="custom/static"+$_Get['route'] //For PHP
Using your mod_rewrite you can fulfill your demands,
RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?route=$1 [L]
But if you need out of box solution using .htaccess then I suggest learning "rewrite-engine" instead of using generating tool

.htaccess RewriteRule is acting strange

I have a webpage, which url looks like this:
http://www.mydomain.com/folder/index.php?title=The_title
The only problem is that I want it to look like one of these:
http://www.mydomain.com/folder/The_title
http://www.mydomain.com/folder/The_title.php
I have searched most of a lot and found one solution, which "works":
RewriteEngine on
RewriteRule ^([^/]*)\.html$ /folder/index.php?title=$1 [L]
It does what it should, except the ending has to be ".html" (or ".kl", if you like). This solution won't accept ".php", which gives me a "500 Internal Server Error". Same thing happens if I try it without the extension.
EDIT:
Forgot to mention that the .htaccess file lies in the folder and not the root.
This will work for you.
RewriteEngine On
RewriteRule ^folder/([^/]*)\.php$ /folder/index.php?title=$1 [L]
So, since I couldn't get it to work properly I took the challange and started reading about mod_rewrite, which led to the solution:
RewriteRule ^(\w+)/?$ index.php?title=$1 [L]
If anyone else run into troubles I'll recommend these sites:
more .htaccess tips and tricks..
An In Depth Guide to mod_rewrite for Apache

htaccess redirect issue mod rewrite

hey well I'm trying to change the url structure using the htaccess file and I'm rewriting my old structure to the new one, although I'm having some issues.
I'm using the following code
RewriteRule video-(.*)-(.*).html?$ http://mysite.com/download-$2-video-$1.html [R=301,L]
Now the problem I'm running into is that when I try to redirect something like
http://mysite.com/video-1-this-is-the-title.html
it's redirecting it to
http://mysite.com/download-this-video-1.html
instead of
http://mysite.com/download-this-is-the-title-video-1.html
if anyone could help that would be great! :)
If the first backreference is always going to be numbers, you could try changing your regular expression to:
RewriteRule video-([0-9]+)-(.+).html?$ http://mysite.com/download-$2-video-$1.html [R=301,L]

Redirecting A Subdirectory and Cleaning the URL using .htaccess

So, this is somewhat of a strange situation. I'm hosting a development server for a person I'm working with in a subfolder of my website. Basically the file structure looks like this:
public_html/my_subfolder/public/index.php
So what I'm attempting to do is make it so that if a user types "www.mysite.com/my_subfolder" they are taken to the "public/index.php" page without the public subfolder appearing in the URL. It's kind of silly that I'm still messing with this, considering it's only a development server.
I'm just at the point where I've messed with it for so long I really want to get it to work now, so that, if nothing else, I'll learn something. Any help would be greatly appreciated!
Try this rule in your .htaccess file:
RewriteEngine on
Options +FollowSymlinks -MultiViews
RewriteCond %{REQUEST_URI} !^/my_subfolder/public [NC]
RewriteRule ^my_subfolder/(.*)$ /my_subfolder/public/$1 [L,NC]
This will redirect everything so make sure to serve your static files like js, css, images etc from my_subfolder/public as well.
try using the P flag
RewriteRule ^/foo(.*) http://bar$1 [P]
Thanks
S

Resources