Seo Friendly URL results in CSS IMG and JS not working
You dont need the second rewrite rule. Your CSS/JS paths are all 'relative' to your current location.
Your CSS exists here:
/css/normalize.css
Your page is looking here:
/swift-details/2/abblinbb/css/normalize.css
All you need is 'forward-slashes' before your CSS/JS paths.
CSS, Images, and JS not loading due to url rewrite
If you don't want to change every instance when you move your site, just update the <head>
section of your html page header and add this
<base href="http://www.example.com/" />
or
<base href="/" />
This will take care of that problem and you don't have to update all instances to absolute paths.
Url friendly without losing styles css / js / images
You need to switch on mod_rewrite and use it. Example:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1.*$ http://example.com/ [R=301,L]
Folder-based example:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^folder1/(.*)$ http://gs.mt-example.com/folder2/$1 [R=301,L]
Your case:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^online.php$ project/online/video/hd/free/$1 [R=301,L]
See more here.
.htaccess rewrite url remove CSS,JS,AND IMAGES Whatever i do its not working
Because you are rewriting rules, you need also to rewrite base href HTML, or just add the full url to your styles,js and images.
Example base href:
<head>
<base href="https://www.yourwebsite.com/">
</head>
can not load css and js after htaccess redirect url in php
As you know, the default bahavior of base is to replace the url(adress) before the relative adress.
example:
<base href="http://www.mywebsite.com/images/" target="_blank">
The browser will look for the image "html5.png" at "http://www.mywebsite.com/images/html5.gif".
Hope it help you !
How to implement friendly URLs without breaking images, CSS and JavaScript?
But the images , css and javascript codes are destroyed
Probably because you are using relative URLs to your static resources. If you are referencing an image as img/myimage.jpg
then the browser is now going to look for /blog/img/myimage.jpg
, not /img/myimage.jpg
as before (using your example).
You need to use root-relative URLs (starting with a slash) or absolute URLs (scheme + hostname) to be able to access the resource from different URL-path depths. You can sometimes work around the issue with a base
element in the head
section, however, there are caveats with this approach.
See my answer to the following question on the Webmasters stack that goes into great detail on this exact issue: .htaccess rewrite URL leads to missing CSS
RewriteRule ^blog/(.*)$ ./blog.php?id=$1
You should remove the ./
prefix on the RewriteRule
substitution. The dot (to indicate the "current directory") serves no purpose here in the URL-path (it gets resolved away).
You should also include the L
flag, if you later add other rules.
You also need to ensure that MutliViews is disabled, otherwise, blog.php
will be "magically" called without the id
attribute and your script will fail. (MultiViews basically enables extensionless URLs but can cause additional issues.) See https://httpd.apache.org/docs/2.4/content-negotiation.html
Optionally, if you are changing a URL structure, you can also redirect URLs of the form /blog.php?id=<value>
to /blog/<value>
in order to preserve SEO and redirect bookmarked links. (But note that you should already be linking to URLs of the form /blog/<value>
throughout.)
For example
# Disable MultiViews
Options -MuliViews
# Redirect "/blog.php?id=<value>" to "/blog/<value>"
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^id=([^&]*)
RewriteRule ^blog\.php$ /blog/%1 [QSD,R=301,L]
# Rewrite "blog/<value>" to "/blog.php?id=<value>"
RewriteRule ^blog/(.*) blog.php?id=$1 [QSA,L]
Additional notes on the above directives:
- The check against the
REDIRECT_STATUS
environment variable ensures that only direct requests are redirected and not rewritten requests by the rewrite that follows. - The
QSD
flag discards the original query string from the request. - The
QSA
flag appends (merges) any query string that might be on the original request with the query string being assigned in the substitution. If you are not expecting any query string then remove this flag. eg. A request for/blog/Blizzard?foo=1
would be internally rewritten to/blog.php?id=Blizzard&foo=1
only if theQSA
flag is present.
Related Topics
Warning: a Non-Numeric Value Encountered
Session Variables Not Working PHP
Should I Manually Check For Errors When Calling "MySQLi_Stmt_Prepare"
How to Check If a Url Exists Via PHP
Is There a Code Obfuscator For PHP
How to Zip a Whole Folder Using PHP
Angularjs Http Post to PHP and Undefined
Strange Behavior of Foreach When Using Reference: Foreach ($A as &$V) { ... }
Use an Array in a MySQLi Prepared Statement: 'Where .. In(..)' Query
How to Filter an Array by a Condition
How to Log Errors and Warnings into a File
Replace Keys in an Array Based on Another Lookup/Mapping Array
PHP MySQLi_Connect: Authentication Method Unknown to the Client [Caching_Sha2_Password]