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://.
Related
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.
Here is my .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /~new/
</IfModule>
Directory structure of my website is this:
Now what I want to do is to be able to visit paths like following:
domain.com/~new/pages/page1.php
But when I try to visit above URL I get redirected to 404 page.
What am I missing? Are ReWriteRule also needed?
RewriteBase doesn't do what you think it does. In fact, by itself it does nothing. RewriteBase is only necessary if you have relative path substitutions in your RewriteRule. And if you aren't doing that (ie. you are using root-relative or absolute paths) then you don't actually need it.
Are ReWriteRule also needed?
Yes, RewriteRule is what actually does the URL rewriting. And you need to do some URL rewriting.
So, basically, you want to internally rewrite your URLs from:
example.com/~new/pages/page1.php (Your "virtual" URL)
to example.com/pages/page1.php (The real URL)
RewriteRule ^~new/(.*) /$1 [L]
The (.*) captures everything after /~new/ and $1 is a backreference to this captured subpattern.
I have 2 main pages. It works like so,
<html>
<body>
<div id='menu'></div>
<div id='content'><?PHP require("content.php"); ?></div>
</body>
</html>
Then, content.php pulls the "page" from the url, and checks it through a url of "good pages". If not, there is a default. Anyway, the typical url looks like this
/index.php?page=user&id=1
/?page=group&id=3
I'm trying to make it look like this
/user/1
/group/3
This is what I have for my .htaccess file, which doesn't work 100%. It pulls the correct page, but the css files doesn't seem to be uploaded. It is in /css/ in the main directory as index and content.
EDIT
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)/(.*)$ /index.php?page=$1&id=$2 [L]
I'd like the application to be scale-able if possible.
Thanks!
You will want to be using either an absolute path to your CSS, or use a base href for it, or you can prefix the path to the CSS with a / if the path to starts from the root domain.
Your .htaccess is fine, but might want some slight tweak:
RewriteEngine On
RewriteRule ^(\w)/([0-9]+)/$ /index.php?page=$1&id=$2 [L,QSA]
please try with the following code you can get the values in the $_GET['page']. Then you can split the values by / and then can get your user name,id etc
RewriteEngine On
RewriteBase /project/
RewriteRule ^([A-Za-z0-9]+){0,1}$ index.php?page=%{REQUEST_URI} [L,NC,QSA]
In the above code you may want to replace the /project/ with /. It will work perfectly
Try this .htaccess code
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/(.*)$ /index.php?page=$1&id=$2 [L]
You can now directly access your webpage via..
www.yourdomain.com/user/1
www.yourdomain.com/group/3
Please try below code in .htaccess
RewriteEngine On
RewriteRule ^user/([0-9]+)/$ /index.php?page=user&id=$2 [L,QSA]
RewriteRule ^group/([0-9]+)/$ /index.php?page=group&id=$2 [L,QSA]
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.
For URL Rewriting, i have got the output for static URL
But , for dynamic URL , i am getting partial output only.
I have placed the .htaccess file in the root directory only.
Here is the code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/price/([0-9]+)/?$ booking.php?price=$1
What will be the solution ?
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/([0-9]+)/?$ booking.php?price=$1
RewriteRule ^booking/([0-9]+)/([0-9]+)/?$ booking.php?price=$1&pass=$2
You really want to customise your code for these though so as to be able to use general rules, rather than converting specific paths to use $_GET.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^booking/([0-9]+)/?$ booking.php?price=$1
RewriteRule ^booking/([0-9]+)/([0-9]+)/?$ booking.php?price=$1&pass=$2
For images and Css you need to define your base folder in htaccess file as
RewriteBase /~your folder/