I know this question has been ask often. I leverage the links here but still cannot get it to work
source: link
what am trying to achieve:
I have Original URL:
Eg: http://localhost/followersid.php?id=101data
which am trying to rewrite as follows
Eg: http://localhost/followers
.htaccess Code
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/\followers$ followersid.php?id=$1
My ISSUE: When I type http://localhost/followers in the url, it says The requested URL was not found on this server whereas followersid.php is in the same directory with .htaccess files
It was a regex issue. this is what solve the problem
RewriteRule ^([a-zA-Z0-9_-]+) followersid.php?id=$1
Related
I'm trying to display SEO friendly URLs by using a rewrite in our .htaccess file, but I can't get it to work (I've researched many of the related topics on StackExhange and elsewhere, but to no avail). I'd like to get the value of the id on this page...
http://199.119.123.135/info/tool_surety_company.php?id=1
...and display the id value in the URL instead of the ugly "tool_surety_company.php?id=1".
I'm going for a result like this: http://199.119.123.135/info/travelers-group
I'm using the following code in my .htaccess file:
RewriteCond %{THE_REQUEST} \ /+info/tool_surety_company\.php\?id=([^&]+)
RewriteRule ^ /info/%1/? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^^info/([^/]+)/?$ /info/tool_surety_company.php?id=$1 [QSA]
But I'm receiving a 404 error.
Any ideas? Thanks in advance!
There might be something I'm misunderstanding here but I believe there would need to be a mechanism on the server side code to load the correct content for the new "seo-friendly url". In other words, sure, you can redirect the user to show a different url but how is the server going to know what content to load for that new url?
Here's a good resource for putting together a simple example.
https://moz.com/ugc/using-mod-rewrite-to-convert-dynamic-urls-to-seo-friendly-urls
Update:
From here - https://mediatemple.net/community/products/dv/204643270/using-htaccess-rewrite-rules
TROUBLESHOOTING
404 Not Found
Examine the new URL in your browser closely. Does it match a file that
exists on the server in the new location specified by the rewrite
rule? You may have to make your rewrite rule more broad (you may be
able to remove the $1 from the second string). This will direct
rewrites to the main index page given in the second string. Or, you
may need to copy files from your old location to the new location.
In other words, the only reason you would be getting a 404 is because the server does not find the file that is requested as defined in the URL visible in your browser address bar.
Htaccess Rewrites are enabled by using the Apache module mod_rewrite,
which is one of the most powerful Apache modules and features
availale. Htaccess Rewrites through mod_rewrite provide the special
ability to Rewrite requests internally as well as Redirect request
externally.
When the url in your browser's location bar stays the same for a
request it is an internal rewrite, when the url changes an external
redirection is taking place. This is one of the first, and one of the
biggest mental-blocks people have when learning about mod_rewrite.
More info from here:
http://www.askapache.com/htaccess/modrewrite-tips-tricks.html
My url is
www.abc.com/cbn/either/index.php
and I want to access this by only current url. When I change the path of the
index.php file, i.e.
www.abc.com/cbn/index.php
Still, I am accessing index.php file which is a bad approach for SEO point of view because now google will index two URLs of the same file. So please help me out to fix this problem.
Add such line in your htaccess after RewriteBase
RewriteRule cbn/index.php /cbn/either/index.php [R,L]
I'm in a situation where my web page have the following types of URL's
http://mysite.com/?type=home
http://mysite.com/?type=aboutus
http://mysite.com/?type=contactus
For the end users I need it to display like the following:
http://mysite.com/home
http://mysite.com/aboutus
http://mysite.com/contactus
This means, the user is not aware that the URL have a request parameter "type" in it.
I'm not sure it is possible or not.
Please help me to get to a solution.
EDIT: I searched lots of websites to learn URL rewrite by using .htaccess, But didnt able to make them working in my server.
Place this in you .htaccess file
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-+/]+)$ ?type=$1
RewriteRule ^([a-zA-Z0-9-+/]+)/$ ?type=$1
Yes it is absolutly possible.
Your have to be sure your hostprovider has enable URL rewriting (I don't really remenber but I'm sur you can find help on Internet to verify that).
You have to create an ".htaccess" file at the root of your site.
Put this content in it :
tell the server to follow symbolic links :
Options +FollowSymlinks
activate the rewrite module :
RewriteEngine on
Rule for rewrite url
RewriteRule ^([a-z]+)$ /index.php?type=$1 [L]
Note this is just a qucik exemple you may want to look "url rewriting tutorial" on Google.
I've seen it before and I have no clue how to do it or what to look for on google to find it.
Basically I'd like to know how to get these shortened urls to work, what i mean is for example
this: http://website.com/index.php?id=666
turned into this: http://website.com/666
Is there some way to do this through php or do people actually go around making maps for each id?
thanks
Hi there depends what server you are on but if you are using a server with apache that has mod rewrite you can use a htaccess rule.
So an example would be:
first create a .htaccess file then paste in the following content:
RewriteEngine on
RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L]
I'm writing my own url shortener. I'm done with everything such as creating short urls. But when I try to browse htt p://example.com/rtr93, I get a 404 error. But http://example.com/index.php/rtr93 works find and shows the relevant page (I'm not redirecting to a new url. I'm just getting the relevant record from database which has a column short_url).
I'm using PHP and syfmony 1.2 if that helps. I think I need to properly setup .htaccess file. But I don't know where to get started.
Something like this should work:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ /index.php [L]
You may want to make the regex more specific if you're planning on hosting other things on the same domain.