Ok, I have a link http://www.cuadmemo.com/posts.php?id=2861 and want it to show like this
http://www.cuadmemo.com/2861
I have in the .htaccess file this.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ posts.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ posts.php?id=$1
Have tried a number of different solutions that I read on this site but none seem to work this far. Any suggestions to fix this would be greatly appreciated.
RewriteEngine On
RewriteBase /
# Make sure we don't rewrite directories and existing files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_-]+)/?$ posts.php?id=$1 [L]
Related
I'm needing some help with my .htaccess file. What I have are pages with the query page=''. I've tried looking up some resources on rewriterule's but haven't found what I need.
So what I'm going for is like:
domain.com/sub/index.php?page=options to domain.com/sub/options.
futhermore I'd really like a trailing / like:
domain.com/sub/options/
Any help or resources to point me to would be appreciated.
Edit:
Have tried:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php?page=$1 [NC,L]
which seems to rewrite everything back to my root index.php
For the redirection, try this:
RewriteEngine On
RewriteBase /sub/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L]
For the trailing slash, you need to add it in your anchors on your pages.
I am currently creating a site in localhost and have no luck in getting redirect working. I want to redirect
http://localhost/s/profile.php?uid=16
to
http://localhost/s/16
How could I go about doing this. I have tried using examples online with no luck.
Edit: I tried
RewriteEngine On
RewriteRule ^([^/]*)\.php$ /s/profile.php?uid=$1 [L]
Using copy and paste from online. I always try to figure out who to use htaccess but can't seem to do so.
Here is the base functionality you are looking for. This is just a simple example and you should certainly do your research on this subject.
Alternatively, there are plenty of generators.
http://www.htaccessredirect.net/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^profile\.php$ - [L,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /profile.php [L,NE]
</IfModule>
You can have this rule
RewriteRule ^s/([^/]*)/?$ /s/profile.php?uid=$1 [L]
In the htaccess file in your "s" folder, try:
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+s/profile\.php\?uid=([^&\ ]+)
RewriteRule ^ /s/%1.php? [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)\.php$ /s/profile.php?uid=$1 [L]
I am trying to use htaccess to remove the sub directory from the url and leave everything else.
The current links look like this...
http://blog.domain.com/blog/page-title
I need the links to look like this...
http://blog.domain.com/page-title
there is an installation of WP at both locations with the same DB (different physical databases)
so I have tried this...
RewriteEngine On
RewriteRule ^$ blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ blog/$1
and lots of other things, just cant seem to work it out with all the attempts.
Would love a little help on this
How about
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/blog
RewriteRule ^(.*)$ blog/$1 [L]
This will make every links like:
http://blog.domain.com/page-title
behave as if they were:
http://blog.domain.com/blog/page-title
And if you want the inverse effect, meaning that all link with /blog/stuff change into /stuff try this instead:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ /$1 [L,R=301]
Currently I have a url
www.mysite.com/folder/details.php?d=sample.com
and I want it to change like this one
www.mysite.com/folder/sample.com
This is my .htaccess file, but it is not working:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ details.php?d=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ details.php?d=$1
I also tried this one, but its not working also:
RewriteEngine On
RewriteRule folder/([0-9]+) details.php?d=$1
This is my url link php code:
<?php echo $var['var']; ?>
I tried some of the answers I found in this site but still I cannot figured out what I am doing wrong. Anyone?
Thanks!
You need some conditions to prevent looping:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9_.-]+)/?$ details.php?d=$1 [L]
You can also combine the two rules into one by using the /? at the end to make the slash optional.
For the rules to be placed in the document root, you need to add the folder names to the pattern and the target:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder/([a-zA-Z0-9_.-]+)/?$ /folder/details.php?d=$1 [L]
Thanks for your comments #Jon Lin and #quasivivo , I found a solution to my problem, this is my htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^portfolio/(.*)$ /portfolio/details.php?d=$1 [L,QSA,NC]
and I also change my url link code:
<?php echo $var['var']; ?>
Hope this will help someone in the future.
I want to make my first api, but im having trouble setting up the urls. The api url is here:
http://tools.fifaguide.com/api/
So for example if some one goes to:
http://tools.fifaguide.com/api/player/messi
Then I need this page to be loaded:
http://tools.fifaguide.com/api/server.php
What do I write in .htaccess? and where should I put it?
This is what I have right now:
RewriteEngine On
RewriteRule ^api http://tools.fifaguide.com/api/server.php
But it doesnt do anything, also the htacces file is in the api folder.
Any help would be really apreciated!
This is what ended up working for me
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api/index.php [QSA,L]
////// wordpress stuff /////////
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
You might try this:
RewriteEngine On
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/server.php [R,L]
And if you need the resulting url you could add this:
RewriteEngine On
RewriteRule ^api/(.*) http://tools.fifaguide.com/api/server.php?r=$1 [R,L]
Then in your script you could access the requested url with $_GET["r"] (assuming php...)
Also a helpful tool i've found for htaccess:
http://htaccess.madewithlove.be/
-Ken