Below code is to make my url look pretty
RewriteEngine on
RewriteRule "^info/(.*)$" "/detail.php?id=$1" [L,NC]
detail.php will retrieve data from database based on ID we send to it, but page will be display as it has no css and JS file
it displays as below:
While it should be like this
Try with this :
Options +FollowSymLinks -MultiViews -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^info/(.*)$ detail.php?id=$1 [L]
And add before your CSS & JS links this: http://example.com/your_files.css
The problem is from your links! Just add domain before them, and everything will work :)
Or just add this to your <head> tag : (Specify a default URL and a default target for all links on a page)
<base href="http://example.com/">
See this, it's the solution to your problem :)
Related
I am trying to make my url from this:
www.domain.com/view.php?id=15
To ths:
www.domain.com/watch/15
My code in htaccess is as follows:
Options -Indexes
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^watch/([^/]+) view.php?id=$1 [NC]
Now if I go to www.domain.com/watch/15 it loads the content but without any js, css because in this case it looks for css and js under /watch folder which doesnt exist..
How do I make this option to work properly? I dont want to create watch folder and copy paste css and js so it will embed properly
You need to add the base tag to the head section of html to fix the css/js problem.
<base href="http://www.yousite.com" />
Then your rules will work fine. I modified them a little as well for good measure.
Options -Indexes +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^watch/([^/]+)/? view.php?id=$1 [NC,L]
i'm learning how to rewrite urls and im trying to do that in my ubuntu server. I managed myselft to activate the Allowoverride All and i have htacess working.
I want to change this url for example:
http://serverismai/myapi/public/rest/navigate.php
And i try to do it like this :
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home(.*)$ myapi/public/rest/curso/navigate.php/$1 [L]
</IfModule>
I've tried various solutions but this was the closest i got. The url dosent change automatically but if i insert http://serverismai/myapi/public/rest/home i see a blank page with some of my website html written ( not even the html of the page i'm trying to rewite url).
I'm pretty new to this so i want to know if there is something wrong in the Rewrite Rule or if my error is somewhere else...
Thank you!
You can use this code in your /myapi/public/rest/.htaccess file:
RewriteEngine On
RewriteBase /myapi/public/rest/
RewriteRule ^home/?$ curso/navigate.php [L,NC]
I am trying to make a friendly url for my website but when i use it, it always uses the current folder as rewrite and not show images, css,...
RewriteEngine On
RewriteOptions inherit
Options +FollowSymlinks
Options -Multiviews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^number/([a-z0-9]+)/?$ /index.php?id=read&num=$1 [L,NC]
and i have result as mydomain.com/number/123456/
but my page not showing with theme because all link js,css,images,... change in to /number/123456/
example: mydomain.com/number/123456/css/style.css or mydomain.com/number/123456/images/logo.png
But all that in root folder is mydomain.com/css and mydomain.com/images ~~!
How can i use with that format and my page can show correctly :(
Any solutions?
Please help me!
I am using OSCLASS script and I am using .htaccess to rewrite the urls. The default .htaccess that OSCLASS makes, gives urls like this ( http://myhost.com/saleon/vehicles/cars/honda-civic_i28 ) I want to add '.htm' at the end of each url. So that my url would look something like this ( http://myhost.com/saleon/vehicles/cars/honda-civic_i28.htm ). Does anyone has a clue how to do that in htaccess. My .htaccess code is as follow:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /saleon/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /saleon/index.php [L]
</IfModule>
Thanks for the help.
There's no need to do that in the .htaccess. You can change that in the oc-admin: Settings > Permalinks and then click on Show rules.
For example, the default permalink for the listing looks like this: {ITEM_TITLE}-i{ITEM_ID} and it generates the url as you mentioned before. However, if you change that value for the following one you will obtain an url ending with .htm: {ITEM_TITLE}-i{ITEM_ID}.htm.
I want to to use flat links like this:
http://somedomain.com/about-us
http://somedomain.com/products-list
http://somedomain.com/product/item
Thus I've used the mod_rewrite rules like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z-]+)?$ /index.php?page=$1 [L]
RewriteRule ^([0-9A-Za-z-]+)/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]
</IfModule>
The first two links are working fine. But whenever I visit the third type of links the images or the css or any js script that are linked as relative path eg. <img src="images/image.jpg"> and About Us.
The browser thinks it is in http://somedomain.com/product/images/image.jpg and http://somedomain.com/product/about-us.
The correct path should be http://somedomain.com/images/image.jpg and http://somedomain.com/about-us
And thus files with relative links are not working.
How to fix this issue? I don't want to use full path instead of relative for all linked files. Please suggest a way by doing some tweaks in the .htaccess
Try escaping your slash:
RewriteRule ^([0-9A-Za-z-]+)\/([0-9A-Za-z-]+)?$ /index.php?page=$1&value=$2 [L]