w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
htaccess rewrite/redirect if last character is NOT a digit or slash
Your rule is correct, but it's blindly redirecting even when it's not supposed to. The URL that you have above is probably not what it's getting rewritten to. You have it as: http://mydomain.com/index.php?url=players/scoresheet/singlegame/ But I'm willing to bet it's really something like: # note the slash here--------v http://mydomain.com/index.php/?url=players/scoresheet/singlegame/ Because after the URI is internally rewritten and routed to /index.php, the rewrite engine loops again and the redirect catches it, and redirects /index.php to /index.php/. So you need to add the same exclusion conditions that you have in your routing rule: So change: Rewritecond %{REQUEST_URI} [^0-9/]$ RewriteRule ^(.*)$ /$1/ [R=301,L] to either: RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{R

Categories : Htaccess

Htaccess to 301 redirect no ending slash to ending slash
Change the rule you have no and remove the ? making the trailing slash a requirement: RewriteRule ^locations/([a-zA-Z0-9_-]+)/$ search.php?type=location&slug=$1 [L] Then add this (before or after): RewriteRule ^locations/([a-zA-Z0-9_-]+)$ /locations/$1/ [L,R=301] to redirect the browser when a request is made without the trailing slash.

Categories : Htaccess

How to redirect a slash url to non slash url using htaccees
Just add a Rewrite Rule as shown below: RewriteEngine on # Remove slashes from incoming URI's that end with slashes. RewriteRule ^/?(.+)/$ /$1 [R=301,L] # Redirect redirect requests to PHP controllers RewriteCond $1 !^(index.php|images|robots.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^/?([^.]+)$ /$1.php [NC,L] This will redirect any requests not to web root that end in slash a slash-cleansed URL with a HTTP 301 header.

Categories : Apache

.htaccess without slash at the end of uri RewriteRule
Yes of course you can use optional slash at end. Just make trailing slash optional in your regex, something like this: RewriteRule ^product/?$ /product.php [L]

Categories : Regex

Using forward slash in htaccess
What about using a rewrite rule ? I'm not sure to understand your project, but something like this may work : RewriteRule ^(.*)/([a-z]*)/([a-z0-9]*)/([a-z]*)$ $1/$2-$3-$4 [L] It will redirect your new URLs to the old ones...

Categories : Htaccess

Htaccess mod_rewrite - slash
Actually problem is indeed placement of trailing slash in your rule. Trailing slash should be made optional in all the rules like this: RewriteRule ^articles/([^/]+)/([^/]+)/?$ /index.php?section=articles&page=$1&id=$2 [L] RewriteRule ^articles/([^/]+)/?$ /index.php?section=articles&page=$1 [L] RewriteRule ^articles/?$ /index.php?section=articles [L]

Categories : Regex

How to remove .php extension and add slash with htaccess
first of all example.com/login.php/register.php is not a valid URL at all, first fix the URL and then TRY ( this will rewrite /register.php URL into /register ) #mod_rewrite RewriteEngine on RewriteBase /[project_root_folder_name]/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^register/?$ register.php [NC]

Categories : PHP

htaccess different behaviour with trailing slash on the URL
You need to think about this from the point of view of the web browser. If the URL does not end with a slash, "/about" for example, then the web browser assumes that it is looking at a file called "about" in the top-level directory of the web server. So any requests in the page generated by "/about" which have relative paths will cause the web browser to produce a full path based on starting off in the top-level directory. For example, a CSS file path of "css/style.css" will cause the browser to start from the top-level and ask for the file from "/css/style.css". But if the URL does end with a slash, "/about/" in our example, then the web browser believes that it is looking at a sub-directory called "about". Now that same CSS file path "css/style.css" will cause the web browser to ask fo

Categories : Apache

.htaccess RewriteRule slash to get parameter
Replace your .htaccess code with this. Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteRule ^(go)/([^.]+).html$ /$1.php?name=$2 [L,QSA,NC]

Categories : Htaccess

Trail slash with multiple htaccess
In the admin directory, add an htaccess file with the following: DirectorySlash Off This makes it so mod_dir won't redirect requests for the directory admin. However, note that there's an important reason why directory slash is "on" by default: Security Warning Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents. If that's ok with you, then that's all that you need. Otherwise, you may need to add a special rule

Categories : Htaccess

htaccess rewrite to use variable with slash
Right now, your trailing slash is being gobbled up by the [^.]+ expression, so you need to make that non-greedy by adding a ? after the +. Otherwise, having multiple slashes in the URI should work with these rules. So this: RewriteRule ^([^.]+)/?$ index.php?p=$1 [NC,L] Needs to be this: RewriteRule ^([^.]+?)/?$ index.php?p=$1 [NC,L] As far as the css goes, you either need to change the css links so that they're absolute URL paths (they start with a / and starts from the document root, e.g. /css/my.css) or you can try adding a relative URL base in the header of your pages: <base href="/"> (or whatever the URL base should be).

Categories : Apache

htaccess simplified and remove need for trailing a slash
Well this is sort of an experiment, it will work as you have said but I believe there may be a better way to do this: RewriteCond %{REQUEST_FILENAME} !/(index.php|_modules|css|files|ico|img|js)/ RewriteRule ^(([^/]*)/?)(([^/]*)/?)(([^/]*)/?)(([^/]*)/?)$ /index.php?p1=$2&p2=$4&p3=$6&p4=$8 [L] Basically I am adding an extra group per entry so you can safely exclude a non existent group. So the first element is required and is $2, the second element becomes $4, the third element becomes $6 and the last element becomes $8. (([^/]*)/?) this basically means that anything not a / that ends or not with / for the outer group and inner group anything not a /. Simplified the rule a bit more: RewriteCond %{REQUEST_FILENAME} !/(index.php|_modules|css|files|ico|img|js)/ RewriteRule ^(

Categories : Htaccess

Htaccess rewrite index with trailing slash or without
Making the trailing slash optional will lead to an infinite loop, since [^/]* will match anything that doesn't include a /, ie it would also match index.php?x=get You can avoid this by making the rule apply conditionally, for example by testing the reqeust URI: RewriteCond %{REQUEST_URI} !^/index.php.* RewriteRule ^([^/]*)/?$ /index.php?x=$1 [L] That way the rule can only apply in case the request URI doesn't start with /index.php

Categories : Htaccess

.htaccess remove .php and force trailing slash
Your condition: RewriteCond %{REQUEST_FILENAME}.php -f will fail if your URL's end with a trailing slash. But if you only have jobs and contact then you'll just want: RewriteEngine On # add trailing slash and redirect browser RewriteRule ^([^/]+)$ /$1/ [L,R=301] RewriteRule ^([^/]+)/$ /$1.php [L] # redirect direct access to php files: RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]+).php RewriteRule ^ /%1/ [L,R=301] Oh and I forgot: RewriteCond %{HTTP_HOST} !^www. [NC] RewriteCond %{HTTP_HOST} ^([^.]+).domain.com$ [NC] RewriteCond %{DOCUMENT_ROOT}/%1.php -f RewriteRule ^ /%1.php [L] Assuming that *.domain.com has the same document root as www.domain.com.

Categories : PHP

URL doesn't work with slash after removing extension using htaccess
The problem is when you add the slash you have news/.php and this is not working. A better solution is to rewrite to a GET variable something like this: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*) index.php?url=$1 [L] Then you can filter the GET variable in your script and include the file or content you need.

Categories : PHP

.htaccess prevent access from all but root (with or without trailing slash)
Solved this by denying access only to files that contain a dot .: # Deny all files. <FilesMatch "."> Order Deny,Allow Deny from all </FilesMatch>

Categories : Apache

htaccess add .html extension for urls with or without trailing slash
This rule: RewriteRule ^(([w/-]+)?[w-])(/|.html)?$ test/index.php?slug=$1 [L] Will trap domain.com/slug-text, domain.com/slug-text/ and domain.com/slug-text.html and send slug-text to /test/index.php inside slug param. If you really want to redirect using [R=301] from old urls to new then use this: RewriteRule ^(([w/-]+)?[w-])/?(?!:.html)$ http://domain.com/$1.html [L,R=301] RewriteRule ^(([w/-]+)?[w-]).html$ test/index.php?slug=$1 [L] Also note that as using explicit redirect bottom rule is modified to trap url's ending with .html It is also advisable (if your .htaccess does not already contain this) to filter conditions for existing files and folders not to be trapped by your redirect rules. Simply add these lines before RewriteRule lines: # existing file RewriteCond %{SCRIPT_F

Categories : PHP

.htaccess URL redirected, clean url, trailing slash, force www
I would go with: RewriteEngine On RewriteCond %{HTTP:Host} !^www.domain.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([w-]+)$ /$1/ [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php?page=$1 [L] ErrorDocument 404 /splash/ Be careful to use 302 (temporary) redirections instead of 301 (permanent) ones during your debugging phase, as your browser would "remember" the permanent redirections and not take into account the new configuration of your website.

Categories : Htaccess

Why everytime I use .load() in AJAX my .ajaxForm() begin to redirect?
You're not using .ajaxForm() correctly. You're not supposed to call it in your click handler, you call it when initializing your form, and it establishes its own submit handler that submits the form using AJAX. $(document).ready(function() { $("#f1").ajaxForm(); }); Since it uses AJAX, the page isn't supposed to be redirected. If you want to redirect to the action attribute of the form, use normal form submission, not .ajaxForm().

Categories : Javascript

.htaccess rewrite cond and rule cannot firgure out extra slash at end
This one seems to work fine for me, give it a try: Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / # To externally redirect /dir/foo.html to /dir/foo RewriteCond %{THE_REQUEST} ^[A-Z]{3,}s([^.]+).(html|phtml) [NC] RewriteRule ^ %1 [R=301,L] # To internally forward /dir/foo to /dir/foo.html RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^([^/]*)/?$ $1.html [L] # To internally forward /dir/foo to /dir/foo.phtml RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.phtml -f RewriteRule ^([^/]*)/?$ $1.phtml [L]

Categories : Apache

Rewrite requests to a directory (w/o a trailing slash) to index.php in .htaccess
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory: DirectorySlash On Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -d RewriteRule (?!^.+?/$)^(.+)$ /$1/index.php [L]

Categories : Apache

htaccess: how to remove file extesion, add trailing slash, and possibly keep the style?
To keep your styles, either change you links to absolute URI's (they start with a /) or add this to the page header: <base href="/" /> The reason why you can't get your styles is because the browser appends a URI base to relative URLs. So say the browser loads this page: http://yourdomain.com/foo/ the rewrite rules will internally rewrite the URI to /foo.html but the browser still thinks it's loading /foo/. The extra slash means the relative URI base is no longer /, but /foo/. So for all relative links, the browser will append /foo/ to the beginning. If you specify that the relative URI base is / then the browser will simply append / (like it does for non-trailing slash pages).

Categories : Htaccess

.htaccess url rewrite - remove .php - add trailing slash - and shorten query strings
I misunderstood you. I though you just needed to truncate the query string. This would pull the page parameter value from the query string and append it to the URL. ? truncates query string as before. Options +FollowSymLinks -MultiViews # Turn mod_rewrite on RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^GET /[^?s]+.php?page=([^&s]+)&? RewriteRule (.*).php$ /$1/%1/? [L,R=301] RewriteRule ^([^/]+)/([^/]+)/$ $1.php?page=$2 [QSA,L]

Categories : PHP

How to access directory's index.php without a trailing slash AND not get 301 redirect
You'd first need to turn off directory slash, but there's a reason why it is very important that there's a trailing slash: Mod_dir docs: Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where mod_autoindex is active (Options +Indexes) and DirectoryIndex is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file.But a request without trailing slash would list the directory contents. That means accessing a directory without a trailing slash will simply list the directory contents instead of serving the default index (e.g. index.php). So if you want to turn directory slash off, you have to make sure to internally r

Categories : PHP

Redirect using .htaccess to redirect multiple old pages and non-www to www
You must take several steps: Edit the home_url and site_url options for the main sites (in wp_options if your table_prefix is "wp_", as you want to change the urls of your main site). Edit the domain of your main blog in wp_blogs to www.your-domain version Edit wp-config DOMAIN CURRENT SITE like this: define('DOMAIN_CURRENT_SITE', 'www.example.com'); //your new www one! Go to wp-admin of your blog and reset permalinks Your RewriteRule is fine, but you can make it more dynamic to use in other sites like this: RewriteCond %{HTTP_HOST} ^example.com RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] Or, if your host multi-domains into the same network, like this: RewriteCond %{HTTP_HOST} ^(example1|example2|exampleN).com RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=30

Categories : Misc

.htaccess - redirect all to index.php, but redirect particular link to another
You have two problems here. First, the more specific rewrite rule has to come before the general one. Second, your specific rewrite rule is backwards. RewriteEngine processes rules from top to bottom, much like a programming if/else if/else. This means that you want to put your catch-all case (aka the ^(.*)$) at the bottom of the list. All rules before this need the [L] attribute to stop further processing after they are matched. For the second part, you want to make the browser link http://www.domain.com/link point to the actual file http://www.domain.com/some_real_page.php. In your sample code, you are doing the opposite. The end result should look like this: RewriteEngine on RewriteCond %{REQUEST_URI} ^/link$ RewriteRule ^(.*)$ some_real_page.php [R=302,L] RewriteCond %{REQ

Categories : Htaccess

QPainter::begin: Widget painting can only begin as a result of a paintEvent
You get the message because painting to the widget's paint device is only allowed inside the paint event. If you use it outside the paint event, there's no guarantee it will work. So, instead of painting inside the mousePressEvent, set a state variable (e.g. isPressed) and call update, passing the widget's rect. This will trigger the paint event, where you can check the state variable and paint the widget accordingly.

Categories : C++

.htaccess rule not excluding existing files when rule has a slash condition
I use the following rule in .htaccess, but this may be too general: RewriteRule ^q/([^/]+)/([^/]+)(/?)$ /path/to/q.php?type=$1&q=$2&{QUERY_STRING} [NC] This may be better for you: RewriteRule ^windows(/?)$ /path/to/windows.php?{QUERY_STRING} [NC] RewriteRule ^windows/([^/]+)(/?)$ /path/to/windows.php?type=$1&{QUERY_STRING} [NC] You will have to change this according to your situation. I haven't tested this, but I hope it is good enough for you to get where you want.

Categories : Htaccess

Text after the last slash, what is my mistake?
php already has a function that does this its called basename $url = "http://mydomain.com/colors/"; echo basename($url); //outputs colors $url = "http://mydomain.com/colors/productname.html"; echo basename($url); //outputs productname.html

Categories : PHP

UIView animation not working on text begin editing in iphone app
try with my bellow code Example.. - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; subView.frame = CGRectMake(0,-200,1024,748); [UIView commitAnimations]; return YES; } and set to 0 like default in textFieldShouldReturn: method like bellow.. - (BOOL)textFieldShouldReturn:(UITextField *)textField { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.3]; subView.frame = CGRectMake(0,0,1024,748); [UIView commitAnimations]; return YES; }

Categories : Iphone

Search text file in MATLAB for a string to begin process
I think your script somehow works, and you were just looking at the wrong variable. I assume that the answer you get is startRow = 9 and not line = 9. Check the variable line. By the way, note that you're not checking an End-of-File, so your while loop might run indefinitely the file doesn't contain your search string. An alternative approach, (which is much simpler in my humble opinion) would be reading all lines at once (each one stored as a separate string) with textscan, and then applying regexp or strfind: %// Read lines from input file fid = fopen(filename, 'r'); C = textscan(fid, '%s', 'Delimiter', ' '); fclose(fid); %// Search a specific string and find all rows containing matches C = strfind(C{1}, 'OptimetricsResult'); rows = find(~cellfun('isempty', C));

Categories : String

Add text to a ToolTip when hovering over a cell that has a slash in it in WPF
You can use two converters and data trigger. First converter to check if text contains slash: public class SlashTextConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value != null && value.ToString().Contains("/")) return true; else return false; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } Second converter to format custom message: public class CustomToolTipMessage : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo c

Categories : Wpf

htaccess: How to redirect non-www url to my www-url
RewriteCond %{HTTP_HOST} ^example.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] edit: RewriteCond %{HTTP_HOST} !^www. RewriteRule (.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] edit 2 Add URL Rewrite Rule To Wordpress this is not helpful?

Categories : Htaccess

Redirect htaccess php
Problem is using $ (end of input) in this regex: RewriteCond %{QUERY_STRING} ^f16%5B0%5D=bla+bla+bla$ Since your query string is: 16%5B0%5D=bla+bla+bla&cPath=72&M_ID=12x Change that line to: RewriteCond %{QUERY_STRING} ^f16%5B0%5D=bla+bla+bla(&|$) Update: Looking at your question I realize that you are using quite a few special characters that need to be escaped. RewriteCond %{QUERY_STRING} ^(f16%5B0%5D)=bla+bla+bla(?:&(.*)|$) [NC] RewriteRule ^(products_filter.php)$ /$1?%1=bla+bla&%2 [L,R=301,NE] PS: It is important to use NE flag here. Otherwise %5B and %5D will be further encoded by Apache.

Categories : Htaccess

htaccess redirect from /foo/bar/ to foo.php?q=bar
Hello i think i got this but the following appends no query even though its there....if someone can point out...it would be nice. Options +FollowSymLinks +MultiViews RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /dosearch.php?q=(.*) HTTP/ RewriteRule ^dosearch.php$ dosearch/%1? [R=302,L] RewriteRule ^dosearch/([^/]+)? dosearch.php?q=$1 [NC,L]

Categories : PHP

How with an htaccess can I redirect an url to a different one
Add this to the htaccess file in your document root: Redirect 301 /product/1283794 /ecom/product/1283794 Pretty easy isn't it? You should take a look at the mod_alias documentation. It's pretty cut and dry, and obvious.

Categories : Htaccess

How to redirect only www with htaccess
You can have a more generic regex pattern if you know your domain will be XXX.com: RewriteEngine On RewriteCond %{HTTP_HOST} ^[^.]+.com$ [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] Or even better: RewriteEngine On RewriteCond %{HTTP_HOST} ^[^.]+.[a-z]{2,4}$ [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

Categories : Htaccess

Redirect one url to another url using .htaccess
RewriteRule doesn't include the query string and doesn't include the http-host. Besides that, the first argument is a regex pattern. Without the http host you would be matching either download/page=download(etc) or downloadpage=download(etc). You'll need 2 rules. One that redirects the ugly url to the nice url. One rule needs to rewrite the nice url to an actual working url: #Rewrite ugly url to nice url RewriteCond %{QUERY_STRING} ^page=download&?(.*)$ RewriteRule ^download/?$ download/show?%1 [R,L] #Now get the nice url to work: RewriteRule ^download/show/?$ download/?page=download [QSA,END] The second rule uses the QSA flag, which means it will append the original query string to the query string in the rewriterule. The END flag stops all rewriting, as the L-flag doesn't do tha

Categories : Apache

404 redirect using .htaccess
ErrorDocument 404 /404.php You can place the 404 error template anywhere you want. For example you could place all error messages in a folder called errormessages ErrorDocument 404 /errormessages/404.php

Categories : Htaccess

.htaccess redirect to url
Remove the second group in brackets and don't escape dots and question mark in the 2-nd part of RewriteRule: RewriteRule ^product/([0-9]+).html$ product.php?id=$1&type=deals [QSA,L] I'm desire to change the url become www.example.com/products/1111.html. I didn't change ^product/ to ^products/, as your php file is called "product.php". But you can do it easily. Now when you input: http://www.example.com/product/1111.html it will be rewritten to: http://www.example.com/product.php?id=1111&type=deals

Categories : PHP



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.