I want to remove forum from url/forum/topic - .htaccess

I will like to change url/forum/topic to url/topic
I want the forum to be removed.. Any rewrite please..
I have this on htaccess
RewriteRule ^forum/([A-Za-z0-9-]+)/([0-9-]+)$ category.php?url=$1&pn=$2 [L] # process user profile
RewriteRule ^forum/([a-zA-Z0-9-/]+)$ category.php?url=$1 [L] # process category
RewriteRule ^forum/([a-zA-Z0-9-/]+)/([a-zA-Z0-9-/]+)$ categoryPagination.php?url=$1&link=$2 [L] # process category
#RewriteRule ^forum/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)$ categoryPagination.php?url=$1&link=$2 [L] # process user profile
RewriteRule ^links/([a-zA-Z0-9-/]+)/?$ pages.php?link=$1 [L] # process user profile
RewriteRule ^([A-Za-z0-9-]+)/([0-9-]+)$ board.php?url=$1&pn=$2 [L] # process user profile
RewriteRule ^([A-Za-z0-9-]+)/?$ board.php?url=$1 [NC,L] # Process board
RewriteRule ^([0-9-]+)/([A-Za-z0-9-]+).html$ readtopic.php?id=$1&title=$2 [NC,L] # Process blog topic
RewriteRule ^([0-9-]+)/([A-Za-z0-9-]+)/?$ readpost.php?id=$1&title=$2 [NC,L] # Process blog posts
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z]+)$ userposts.php?user=$1&type=$2 [L] # Process blog posts
#RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ category.php?title=$1&id=$2 [NC,L] # Process blog posts
And i have something like this in some files
<span class="tags"><?php echo $dsname; ?></span>
And
$url="forum/".$url;
<a href="'.WEBROOT.'/forum/'.$slink.'">
etc.
I will like to change https://espbase.com/forum/games to https://espbase.com/games
I come across this on stackoverflow: can i use this and does it need any changes

Related

change the website URL with .htaccess from example.com/post.php?slug=test to example.com/post/test many times

I have a PHP website contains three types of posts
normal blog Post
university post (descrip university)
scholarship post (gives info about a scholarship)
so now my website urls like:
example.com/university.php?post-slug=hvd
example.com/scholarship.php?post-slug=sch
example.com/new.php?post-slug=test
and I want it like
example.com/university/hvd
example.com/scholarship/sch
example.com/new/test
Please gimme the full .htaccess code beacause I don't know edit or coding it
my .htaccess (Only have SSL redictor ):
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:asct.me
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (www\.)?asct.me
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# DO NOT REMOVE THIS LINE AND THE LINES BELLOW SSL_REDIRECT:asct.me
#rewrite for university.php
RewriteRule ^uni/([0-9a-zA-Z-]+) university.php?post-slug=$1 [NC,L]
#rewrite for scholarship.php
RewriteRule ^schlr/([0-9a-zA-Z-]+) scholarship.php?post-slug=$1 [NC,L]
#rewrite for new.php
RewriteRule ^blog/([0-9a-zA-Z-]+) new.php?post-slug=$1 [NC,L]

.htaccess detect "/logged-in" at end of any URL and redirect to same URL

I'd like to know how to create a .htaccess rewrite rule that can check for "/logged-in" at the end of any pretty URL, and then pass a GET parameter back to that same page.
Essentially the user can log in on any page, then the page reloads with /logged-in attached to it. I need to run some PHP that checks:
if ($_GET['mode'] == 'logged-in')
to display a modal on the page they were on confirming the login.
It can be any page on the site, any level deep.
So an example URL might be:
www.domain.com/shop/category-id/logged-in
which would need to rewrite to:
www.domain.com/shop/category-id/?mode=logged-in
Obviously the above URL is already being rewritten prior to this as it is actually loading:
www.domain.com/shop/category.php?id=category-id
So essentially need to know how to detect:
*/logged-in
and get back to
*/?mode=logged-in
while keeping the URL pretty.
Here are the current rewrite rules. ALL of these need to also support placing /logged-in at the end of them, and I was hoping I wouldn't have to manually make a new rewrite rule for each one.
# BLOG
RewriteRule ^blog/page/([0-9]+)/?$ blog.php?page=$1 [NC,L]
RewriteRule ^blog/([A-Za-z0-9-_]+)/?$ blog.php?cat=$1 [NC,L]
RewriteRule ^blog/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ blog-post.php?cat=$1&url=$2 [NC,L]
# SHOP API
RewriteRule ^shop/cart/add/([0-9]+)/([0-9]+)?/?$ shop/?mode=add2cart&id=$1&sku=$2 [NC,L]
RewriteRule ^shop/cart/update/([0-9]+)/([0-9]+)/([0-9]+)/?$ shop/?mode=updatecartitemcount&id=$1&sku=$2&count=$3 [NC,L]
RewriteRule ^shop/cart/remove/([0-9]+)/([0-9]+)/?$ shop/?mode=updatecartitemcount&id=$1&sku=$2&count=0 [NC,L]
RewriteRule ^shop/(generate_token)/?$ shop/?mode=$1 [NC,L]
RewriteRule ^shop/(get_details)/([0-9]+)/?$ shop/?mode=$1&id=$2 [NC,L]
# SHOP
RewriteRule ^shop/([A-Za-z0-9-_]+)/?$ shop/category.php?cat=$1 [NC,L,QSA]
RewriteRule ^shop/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/?$ shop/category.php?cat=$1&subcat=$2 [NC,L,QSA]
RewriteRule ^shop/([A-Za-z0-9-_]+)/([A-Za-z0-9-_]+)/([0-9-_]+)?/?$ shop/product.php?cat=$1&url=$2&id=$3 [NC,L,QSA]
RewriteRule ^policies/([A-Za-z0-9-_]+)/?$ policy.php?url=$1 [NC,L]
# CHECKOUT
RewriteRule ^checkout/(review)?/?$ checkout/index.php?view=review [NC,L]
RewriteRule ^checkout/(checkout|payment|complete)/?$ checkout/index.php?view=$1 [NC,L]
RewriteRule ^checkout/load/([A-Za-z0-9-_]+)/?$ checkout/index.php?mode=load_content&view=$1 [NC,L]
RewriteRule ^checkout/(redeem_coupon|get_total|generate_token)/?$ checkout/index.php?mode=$1 [NC,L]
RewriteRule ^checkout/update_shipping/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ checkout/index.php?mode=update_shipping&view=$1&country=$2&shipping_type=$3 [NC,L]
# USER ACCOUNTS
RewriteRule ^account/order/([0-9-_]+)/?$ view-order.php?id=$1 [NC,L]
RewriteRule ^account/order/([0-9-_]+)/print-invoice/?$ view-order.php?id=$1&mode=print-invoice [NC,L]
RewriteRule ^account/update/([A-Za-z0-9-_]+)/?$ account.php?mode=update&section=$1 [NC,L]
RewriteRule ^forgot-my-password/submit/?$ forgot-my-password.php?mode=submit [NC,L]
RewriteRule ^update-password/([A-Za-z0-9-_]+)/?$ forgot-my-password.php?hash=$1 [NC,L]
RewriteRule ^update-password/([A-Za-z0-9-_]+)/submit/?$ forgot-my-password.php?mode=reset-password&hash=$1 [NC,L]
RewriteRule ^register/submit/?$ index.php?mode=register [NC,L]
RewriteRule ^login/submit/?$ index.php?mode=login [NC,L]
RewriteRule ^logout/?$ index.php?mode=logout [NC,L]
RewriteRule ^logged-out/?$ index.php?mode=logged-out [NC,L]
RewriteRule ^subscribe/?$ index.php?mode=newsletter-subscribe [NC,L]
RewriteRule ^confirm/([A-Za-z0-9-_]+)/?$ index.php?mode=newsletter-confirm&code=$1 [NC,L]
RewriteRule ^confirm-account/([A-Za-z0-9-_]+)/?$ index.php?mode=account-confirm&code=$1 [NC,L]
RewriteRule ^contact/submit/?$ contact.php?mode=submit [NC,L]
# SEARCH RESULTS
RewriteRule ^search/?([A-Za-z0-9-_+]+)?/?$ search-results.php?query=$1 [NC,L]
RewriteRule ^search/([A-Za-z0-9-_+]+)/(render_results)/?$ search-results.php?query=$1&mode=$2 [NC,L]
Scott
You can use this rule just below RewriteEngine On line:
RewriteEngine On
RewriteRule ^(.+)/(logged-in)/?$ $1?mode=$2 [L,QSA,NC]
# all your rules go below this line

Using wildcard on other page addresses than the static ones

I want to use a wildcard so any page addresses are allowed. But I want to use some static page addresses like user login, registration, and some more. I'm currently using this method but it will, as I expected, try to find page.php on every page address.
# KONTO
RewriteRule ^skapa-ett-konto$ account-create.php [L]
RewriteRule ^logga-ut$ account-logout.php [L]
# KONTO: Sidor som behöver laddas in genom jQuery/AJAX
RewriteRule ^slutfor-registreringen$ configurations/javascripts/ajax-form/account-create.php [L]
RewriteRule ^logga-in$ configurations/javascripts/ajax-form/account-login.php [L]
# --------------------------------------- #
# PROFIL
RewriteRule ^anvandare/([a-z0-9]+)$ profile.php?u=$1 [L]
# --------------------------------------- #
# ENSKILDA FILER
RewriteRule ^(.*)$ page.php?p=$1 [L]
How can I make so RewriteRule use wildcard to other page addresses than for the static ones?
Thanks in advance.
If I understood right, you want to exclude some existing pages like login and registration from the last rule. The way to exclude them is like this:
# ENSKILDA FILER
# Add other pages to exclude here
RewriteCond %{REQUEST_URI} !(page\.php|login|registration) [NC]
RewriteRule ^(.*)$ page.php?p=$1 [L]
If all other addresses are not files, you can prefix your page.php rule with
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* page.php?p=$0 [L]

.htaccess redirection rule for site

I need help with htaccess URL rewriting for my site.
Problem is that just first page in some category has nice cruft free URL, and all other pages has dirty URLs.
For example first page has link like this:
http://www.my-site-name.com/Category-name/Subcategory-name/
But page 2, and any other pages are like this:
http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=2
http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=3
So, I need some SEO friendly htaccess redirect rule to make URLs like this:
http://www.my-site-name.com/Category-name/Subcategory-name-page-X/
or like this
http://www.my-site-name.com/Category-name/Subcategory-name/X/
But probably I would like first more.
This is part of .htaccess for that: (I just added full content, maybe there is something more about it.
## For top rated items
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L]
## For latest items
RewriteRule ^latest/recent-page-(.*)/$ latest.php?page=$1 [L]
## For show most rated - most clicked - most downloaded and most searched items
RewriteRule ^most-rated.html$ showmost.php?type=1 [L]
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L]
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L]
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L]
## For showing category of item
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L]
## For showing subcategory of item
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L]
## For showig item
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L]
## this section should be inserted just after the showing item rule above
#if the query string has cat, sub_cat and Img
RewriteCond %{QUERY_STRING} ^cat=(.+)&sub_cat=(.+)&img=(.+)$ [NC]
#and it is for resource show.php, then 301 redirect to Keyword rich URL
RewriteRule ^show\.php$ http://www.my-site-name.com/%1/%2/%3.html? [NC,L,R=301]
I also cleaned it up a little
#don't rewrite if file or dir exists
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
## For showing category of item
RewriteRule ^([^/]*)/$ showcat.php?cat=$1 [L]
## For showing paged subcategory of item
RewriteRule ^([^/]*)/([^/]*)-page-([0-9]+)/$ showcat.php?cat=$1&subcat=$2&page=$3 [L]
## For showing subcategory of item
RewriteRule ^([^/]*)/([^/]*)/$ showcat.php?cat=$1&subcat=$2&page=1 [L]
## For showig item
RewriteRule ^([^/]*)/([^/]*)/([^/]*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L]

mod_rewrite, not rewriting when making a change

My mod_rewriting seems to be being messed up by this one line at the end of my .htaccess file, and I can't for the life of me work out why.
RewriteEngine ON
Options FollowSymLinks
# User profile with username specified
RewriteRule ^([a-z0-9_.-]{1,30}+)$ profile.php?username=$1 [NC,L]
I want to match usernames, but allow them to have a-z 0-9 (no case) and also allow underscores, dots and hyphens.
It works fine without the '_.-'
I've tried escaping them too, but to no avail.
EDIT:
It seems that the problem with the rewrite, is that it is causing my 'styles.css' file to be rewritten, even though I've got it set to NOT rewrite, if the file or directory exists.
Here's the whole .htaccess file...
RewriteEngine ON
Options FollowSymLinks
# Only rewrite for folders and directories that don't exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Remove www.
RewriteCond %{HTTP_HOST} ^www.nitpicker.me$ [NC]
RewriteRule ^(.*)$ http://nitpicker.me/$1 [R=301]
# Remove the trailing slash if there is one
RewriteRule ^(.+)/$ $1
# Main pages
RewriteRule ^(stream|settings|comment|profile)(.php)?$ $1.php [QSA,L]
# Find friends page
RewriteRule ^friends$ findfriends.php [L]
RewriteRule ^subject-([0-9]+)$ page.php?subject_id=$1 [QSA,L]
RewriteRule ^nit-([0-9]+)$ comment.php?nit_id=$1
RewriteRule ^search-([a-z0-9]+)$ search.php?term=$1 [NC,L]
# The initial sign up page with invite code
RewriteRule ^signup(-([a-z0-9]+))?$ signup.php?invite=$2 [NC,L]
# Trending page
RewriteRule ^(newest|trending|most_picked) trending.php?select=$1 [QSA,L]
# User profile with username specified
RewriteRule ^([a-z0-9\-_\.]{1,30}+)$ profile.php?username=$1 [NC,L]
How can I get it to stop it rewriting my '/styles.css' file?
use this:
# User profile with username specified
RewriteCond %{REQUEST_URI} !^.*\.css.*$ [NC]
RewriteRule ^([a-z0-9\-_\.]{1,30}+)$ profile.php?username=$1 [NC,L]

Resources