.htaccess friendly urls - php

I got a problem with my .htaccess I want to create a friendly url, I tried many ways esp. some of the ways are found on this site, but still it isn't working..
Heres my code:
Options +FollowSymLinks +SymLinksIfOwnerMatch -Indexes
Header unset ETag
FileETag None
RewriteEngine On
RewriteBase /
RewriteOptions Inherit
RewriteRule .* index.php
#friendly urls
RewriteRule ^styles/style.css$ /view/style.php
RewriteRule ^styles/style.css$ view/style.php

Without knowing exactly how it's not working for you I can see a big issue.
RewriteRule .* index.php
That rule matches anything. So by the time you get down to your 'friendly urls' section, the url has changed to 'index.php' which of course doesn't match.
Move the catch-all line below your 'friendly urls' section and add [L] to each of your friendly url rewrite rules.

Related

url rewriting with .htaccess

I'm trying to rewrite the url on a site I have on localhost (port 8000), I have already set this up for certain other directorys but I can't manage to do it for this one. I compared it to several other working .htaccess files but there wasn't any difference. (The module is activated.) The site is in a subdirectory called HTF and the file single.php works just fine. The htaccess file is placed in the same directory.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule videos/([0-9]+)/$ /HTF/single.php?id=$1 [L]
I would like to get an url like localhost:8000/HTF/video/1232434 for exemple.
Any help appreciated, tested several types of htacces files, here a working exemple for a other subdirectory called sorted:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^image-post/([0-9]+)/(.+)\.php$ /sorted/image-post.php? id=$1&title=$2 [L]
RewriteRule ^pages/([0-9]+)/(.+)\.php$ /sorted/page.php?page_number=$1&cat=$2 [L]
Your rule will match videos, not video as you were wanting. Also it will only match with a trailing slash.
This will work
RewriteEngine on
RewriteRule ^video/([0-9]+)/?$ single.php?id=$1
localhost:8000/HTF/video/1232434
will not match
videos/([0-9]+)/$
because of the trailing slash /. Try /? to make the slash optional or leave away. And videos.
^/HTF/video/([0-9]+)/?$ /HTF/single.php?id=$1 [L]
or
^/HTF/video/([0-9]+)$ /HTF/single.php?id=$1 [L]
This shall do the job. Sorry can not try here.

How to create clean url using .htaccess

This is my .htaaccess code.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9]+)/$ movie.php?name=$1
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.in$
RewriteRule ^/?$ "http\:\/\/example\.in" [R=301,L]
ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None
I need clean url for my website.
I've referred lots of tutorials and forums and created the above code.
But not working.. Almost I'm fighting with code.
I dont understand the clean url concept clearly. Is there any codings I ve to write on my php page.
<a href='movie.php?name=titanic'> Titanic </a>
I've this link in my index.php file.
I want example.in/movie/titanic while click the link Titanic.
Also I want to get the value by $_[request].
What exactly I've to do. Please dont make this question as duplicate, I've searched a lot and didn't got the concept clearly. Please help me out.
Thanks
Replace your code with this:
ErrorDocument 404 /404.php
AddDefaultCharset UTF-8
Header unset ETag
FileETag None
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+movie\.php\?name=([^\s&]+) [NC]
RewriteRule ^ movie/%1? [R=301,L]
RewriteRule ^movie/([^/]+)/?$ movie.php?name=$1 [L,QSA]
If you're want to have clean URLs, then you have to use clean URLs in your html code, e.g. use
Titanic
Your rewrite rules will take that doesn't-really-exist-on-the-server address (you don't really have a /movie directory that contains a titanic file, after all), and translates it in to the actual
/movie.php?name=titanic
The user would never see this url, however, because the rewrite would take place purely within Apache. As long as the HTML you send to the user contains only "clean" urls, they'll never see the query strings.
RewriteEngine on
RewriteRule ^movie/([0-9a-zA-Z]+)$ movie.php?name=$1 [L]
Add above code in .htaccess file

rewrite url doesn't include layout?

I'm currently trying to make SEO friendly url's for my website using this script:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^show/([0-9]+)/$ show.php?phto=$1
RewriteRule ^index/$ index.php
So i've tested some things, and i've came up with these problems:
When i visit my website : blalba.com/index/ my layout file wouldn't include/show up. (using an layout.inc.php header/footer system)
Also how can i make it that the user can visit it with index and index/
I'm not so good at this..
Grz
Change your rule with this code (to make trailing slash optional):
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteRule ^show/([0-9]+)/?$ show.php?phto=$1 [L,QSA,NC]
RewriteRule ^index/?$ index.php [L,QSA,NC]
Also make sure for including style, js, images etc always use absolute path i.e. it should start with / or http://.

Hide a part of a URL with mod_rewrite but keep the argument

I would like to write a rule where the members/show/ string will be hidden in the URL.
The original URL: localhost:8080/sandbox/member/show/helloworld, where helloworld is the name of the account. I'd like it to be localhost:8080/sandbox/m/helloworld. Basically, the content delivered will be from the full url, but I'd like it to be hidden for any user.
RewriteRule ^.*$ member/show/$0 [L,QSA] doesn't seem to work, it throws a 500 Internal Server Error. I work with the CodeIgniter Framework, and the following rewrite rule is already present: RewriteRule .* index.php/$0 [PT,L].
I tried several RewriteRule options but without success. I'd be very glad if anyone could shed some light related to my question.
Best regards.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^(sandbox)/m/([^/]+)/?$ /$1/member/show/$2 [L,NC]

Rewriting urls with mod_rewrite - GET variables

I found out I could make clean urls with mod_rewrite. I managed to make pages like /home.php viewable by visiting /home (without .php).
Now, I'd like to turn view_album.php?album_id=23 into album/23
This is the code I use, but sadly it's not working:
Options SymLinksIfOwnerMatch MultiViews
RewriteEngine On
RewriteBase /beta/
RewriteRule ^album/(.*)/ view_album.php?album_id=$1
Thanks in advance.
use
RewriteEngine On
RewriteBase /beta/
RewriteRule ^album/([0-9]*)$ view_album.php?album_id=$1
and make sure you only rewrite if a noting or a number follows album/, so your can access your images, which may be in a folder named album.

Categories